use input_collapsed instead of collapsed, which is used by the method that collapses the ouput of a code cell.