Panel plots are not updating from widget inputs

Hi,
I’m trying to build a POC app with a map (plotly.choropleth_mapbox) that updates given inputs from widgets (a slider, a text box, a dropdown). The map appears to reload, (blinks) but does not update with any of the information.

In searching docs for an answer I see that even the examples from the documentation
(https://panel.holoviz.org/getting_started/Introduction.html) do not update.
I can see the chart, I can toggle the widgets, but the chart does not update.

import panel.widgets as pnw

variable  = pnw.RadioButtonGroup(name='variable', value='Temperature', 
                                 options=list(data.columns))
window  = pnw.IntSlider(name='window', value=10, start=1, end=60)

@pn.depends(variable, window)
def reactive_outliers(variable, window):
    return find_outliers(variable, window, 10)

widgets   = pn.Column("<br>\n# Room occupancy", variable, window)
occupancy = pn.Row(reactive_outliers, widgets)
occupancy

I can’t seem to find any examples from the docs that will update the chart to make it responsive to inputs.

plotly 4.14.3
panel 0.10.3
hvplot 0.7.0
holoviz 0.11.3
nodejs 10.13.0
jupyter lab 2.2.6
Mac OS 10.15.6

Hi @jamjahal

Welcome to the community and thanks for your question.

To get all the examples working you would need to run the examples locally on your laptop. What you see on the website is just static versions of notebooks. It was also confusing to me at first.

As I understand it, Panel does not have the resources to run live python servers to the extent necessary. If you want to checkout live apps, you can check out my site awesome-panel.org.

You can see this fact both at the top of the document you link to and also in the margin on the right side.

An example that works locally is

import panel as pn
import panel.widgets as pnw
import pandas as pd;
import numpy as np
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvas

DATA_URL = "https://raw.githubusercontent.com/LuisM78/Occupancy-detection-data/master/datatraining.txt"

data = pd.read_csv(DATA_URL)
data['date'] = data.date.astype('datetime64[ns]')
data = data.set_index('date')

variable  = pnw.RadioButtonGroup(name='variable', value='Temperature',
                                 options=list(data.columns))
window  = pnw.IntSlider(name='window', value=10, start=1, end=60)

def mpl_plot(avg, highlight):
    fig = Figure()
    FigureCanvas(fig) # not needed in mpl >= 3.1
    ax = fig.add_subplot()
    avg.plot(ax=ax)
    if len(highlight): highlight.plot(style='o', ax=ax)
    return fig

def find_outliers(variable='Temperature', window=30, sigma=10, view_fn=mpl_plot):
    avg = data[variable].rolling(window=window).mean()
    residual = data[variable] - avg
    std = residual.rolling(window=window).std()
    outliers = (np.abs(residual) > std * sigma)
    return view_fn(avg, avg[outliers])

@pn.depends(variable, window)
def reactive_outliers(variable, window):
    return find_outliers(variable, window, 10)

widgets   = pn.Column("<br>\n# Room occupancy", variable, window)
occupancy = pn.Row(reactive_outliers, widgets)
occupancy.servable()

I’ve created a request on Github to make the getting started section more beginner friendly :slight_smile:. Feel free to add your suggestions.

1 Like

Hi @jamjahal, I opened a github issue a few weeks ago because of the same problem. I managed to fix that by upgrading jupyter see this psot: Cannot get the getting started example to update the figure

1 Like

Thanks for your response Marc. I saw the notices about the static notebook. It seems like the examples on the Intro site should function as expected there, but It sounds like that is another issue.

My problem is that the code on the intro page does not respond when running on my own laptop. When running the code locally, the chart still does not respond to inputs from widgets. The same goes for the code that you posted…(which btw barked that I needed to include pn.extension() for it to run. :wink: )

I also tried your code on the bokeh server, which adds another level of complexity, as it does not even show the chart at all.

@lhoupert Thank you as well, however upgrading to jupyterlab 3.0.5 did not work either. The charts do not respond in the notebook to widget toggles, much like in the actual Introduction page.

Hey! I was encountering the same problem and was able to solve it by adding pn.extension(comms='ipywidgets') Hope it could solve your problem as well!

2 Likes