0

I can see how you can change the width of the output cells in JupyterLab, using the approach laid out here. I have tried this and it works. However, I would like to do the opposite - to get the current value of the output cell, as a python variable, that I can then use to resize plots, tables and other elements.

The code below worked in Jupyter Notebook:

from IPython.display import display, HTML
js = """<script>
IPython.notebook.kernel.execute("cell_width="+($( ".cell").width()))
</script>"""
display(HTML(js))
display(cell_width)

But this does not work in JupyterLab, yielding the following error:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[8], line 6
      2 js = """<script>
      3 IPython.notebook.kernel.execute("cell_width="+($( ".cell").width()))
      4 </script>"""
      5 display(HTML(js))
----> 6 display(cell_width)

NameError: name 'cell_width' is not defined

I am using JupyterLab version 4.0.3 and Python 3.10.12

I would be grateful for any ideas that might fix this!

  • Does this answer your question? [How to change the style/width of cells in JupyterLab?](https://stackoverflow.com/questions/66276361/how-to-change-the-style-width-of-cells-in-jupyterlab) – krassowski Jul 29 '23 at 19:26
  • Though a chance is, in JupyterLab 4.1 it will be easier to specify custom styles. – krassowski Jul 29 '23 at 19:27

0 Answers0