Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Plotly output inline (in jupyterlab mode) doesn't work (only able to write plots to external html with full path) #546

Open
ppenguin opened this issue Oct 17, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@ppenguin
Copy link

ppenguin commented Oct 17, 2024

Current Behavior

When trying to make plots in a jupyter python notebook with plotly, only explorting the plot to html work.

Given the following config:

{pkgs, ...}: {
  kernel.python.plotly = {
    enable = true;
    displayName = "Plotly Graph Tester";
    extraPackages = ps:
      with ps; [
        numpy
        scipy
        plotly
        pandas
        odfpy
        nbformat
        chart-studio
        ipywidgets
      ];
  };
}

The following example plot

import plotly.express as px
import plotly.io as pio

pio.renderers.default = "jupyterlab"

df = px.data.gapminder()
fig = px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
           size="pop", color="continent", hover_name="country",
           log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])

fig.show()

fails with (browser console output):

Traceback (most recent call last):
  File "/nix/store/i2ihlpzkbcysdyq8srhh3xlpmv6cskgy-python3-3.10.9-env/lib/python3.10/site-packages/tornado/web.py", line 1711, in _execute
    result = method(*self.path_args, **self.path_kwargs)
  File "/nix/store/i2ihlpzkbcysdyq8srhh3xlpmv6cskgy-python3-3.10.9-env/lib/python3.10/site-packages/tornado/web.py", line 3208, in wrapper
    return method(self, *args, **kwargs)
  File "/nix/store/i2ihlpzkbcysdyq8srhh3xlpmv6cskgy-python3-3.10.9-env/lib/python3.10/site-packages/jupyter_server/auth/decorator.py", line 63, in inner
    return method(self, *args, **kwargs)
  File "/nix/store/i2ihlpzkbcysdyq8srhh3xlpmv6cskgy-python3-3.10.9-env/lib/python3.10/site-packages/jupyter_server/services/config/handlers.py", line 40, in patch
    section = self.config_manager.update(section_name, new_data)
  File "/nix/store/i2ihlpzkbcysdyq8srhh3xlpmv6cskgy-python3-3.10.9-env/lib/python3.10/site-packages/jupyter_server/services/config/manager.py", line 38, in update
    return self.write_config_manager.update(section_name, new_data)
  File "/nix/store/i2ihlpzkbcysdyq8srhh3xlpmv6cskgy-python3-3.10.9-env/lib/python3.10/site-packages/jupyter_server/config_manager.py", line 129, in update
    self.set(section_name, data)
  File "/nix/store/i2ihlpzkbcysdyq8srhh3xlpmv6cskgy-python3-3.10.9-env/lib/python3.10/site-packages/jupyter_server/config_manager.py", line 108, in set
    self.ensure_config_dir_exists()
  File "/nix/store/i2ihlpzkbcysdyq8srhh3xlpmv6cskgy-python3-3.10.9-env/lib/python3.10/site-packages/jupyter_server/config_manager.py", line 62, in ensure_config_dir_exists
    os.makedirs(self.config_dir, 0o755)
  File "/nix/store/abax98471z8fshv4b9p46bkh3lxmpy0z-python3-3.10.9/lib/python3.10/os.py", line 225, in makedirs
    mkdir(name, mode)
OSError: [Errno 30] Read-only file system: '/nix/store/ka67xr3wflf6r3x26mplrzc665y1lix4-jupyter-dir/config/serverconfig'

The only way to actually get a plot I can see is to do:

import plotly.express as px
import plotly.io as pio
import plotly.offline as po

df = px.data.gapminder()
fig = px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
           size="pop", color="continent", hover_name="country",
           log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])

po.plot(fig, filename='/home/jeroen/devel/playgnd/jupyenv/plotly/test3.html')

and open the html in a browser.

Expected Behavior

Using

pio.renderers.default = "jupyterlab"

renders the plot in the notebook.

Steps To Reproduce

Run flake with above kernel config.

OS

- system: `"x86_64-linux"`
 - host os: `Linux 6.10.9-zen1, NixOS, 24.11 (Vicuna), 24.11.20241009.5633bcf`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Lix, like Nix) 2.91.0
System type: x86_64-linux
Additional system types: aarch64-linux, i686-linux
Features: gc, signed-caches
System configuration file: /etc/nix/nix.conf


### Version

master

### Additional Context

This seems to be a broader issue with any packages expecting to write to the python environment.
Probably the "correct" way to solve this is to be able to provide a "normal" (i.e. non-nix-store) state-directory that extensions should write to.

### Relevant log output

_No response_
@ppenguin ppenguin added the bug Something isn't working label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants