Setting the gv.extension has global effect on other notebooks that are served by Panel

I have 2 notebooks that are being served with Panel via “panel serve” command in CLI. Both have maps that are plotted. Both are Jupyter Notebooks that have the .servable() added to their Panel objects.
Notebook A allows users to toggle the map plotting to be either bokeh or matplotlib via Radio menu. In the code, the gv.extension() function is assigned whatever the user selected (bokeh or matplotlib). For some reason this change is also applying to Notebook B, as the map that Notebook B plots changes to whatever is selected on Notebook A.
Since these two notebooks are served with Panel via CLI and with the .servable() they should not be sharing session data and should all be unique apps. So should setting the gv.extension be applying to all the other notebooks in the Panel server? I am a bit unsure if this is an intended function.

1 Like

Hi @antallnguyen

Welcome to the community.

Do you serve to two notebooks together panel serve note1.ipynb note2.ipynb or indidiviually panel serve note1.ipynb + panel serve note2.ipynb?

Hi Marc, thank you for the welcome!

The notebooks are in a folder that panel is serving:
ex. panel serve app/*.ipynb

Hi @antallnguyen

When you use gv.extension (or hv.extension or pn.extension) you actually change a global configuration object. Its an advantage if you want to use one plotting backend for all users and apps that you only have to set it once. But in your situation its not.

You will need to use a method to set the plotting backend that is not global.

For example the pn.pane.HoloViews pane supports a backend argument. See HoloViews — Panel v0.14.4 (holoviz.org).

Global Change

Here is an example replicating your problem.

app1.py

import panel as pn
import holoviews as hv
import pandas as pd

pn.extension("plotly")
hv.extension("bokeh", "plotly")

data = pd.DataFrame({"x": [1,2,3], "y": [1,2,3]})

backend = pn.widgets.Select(options=["bokeh", "plotly"])

@pn.depends(backend)
def plot(backend):
    hv.extension(backend)
    return hv.Bars(data, kdims="x", vdims="y")

pn.Column(backend,plot).servable()

app2.py

import panel as pn
import holoviews as hv
import pandas as pd

pn.extension()
hv.extension("bokeh")

data = pd.DataFrame({"x": [1,2,3], "y": [1,2,3]})

update = pn.widgets.Button(name="Update")

@pn.depends(update)
def plot(event):
    return hv.Bars(data, kdims="x", vdims="y")

pn.Column(update, plot).servable()
panel serve app1.py app2.py

global-configuration-backend

Session Change

If you update app1.py to

import panel as pn
import holoviews as hv
import pandas as pd

pn.extension("plotly")
hv.extension("bokeh", "plotly")

data = pd.DataFrame({"x": [1,2,3], "y": [1,2,3]})

plot = hv.Bars(data, kdims="x", vdims="y")
plot_pane = pn.pane.HoloViews(plot)
backend = pn.widgets.Select.from_param(plot_pane.param.backend, options=["bokeh", "plotly"])

pn.Column(backend,plot_pane).servable()

You will not change the backend globally.

local-backend

1 Like

I see. Thank you for clarifying that the gv.extension changes are applied globally. I was initially a bit confused with this because according to Panel documentation, all notebooks served through “panel serve” would have independent sessions and it seemed strange to me that the gv.extension would be overriding this aspect. But I guess I must have misunderstood and should have read a bit more of the documentation.

Anyways, I have applied your solution to my case and its working as I hoped.

Thanks again for you assistance!

1 Like