Dropdown widget and altair - best practice for speed


I have a relatively complex altair visualisation (concatenation of charts with various selections), and I’m looking to pair it with panel dropdowns. Basically, the dropdowns are to select different datasets. Each dataset has 1-3k rows, so loading takes quite a while. Below is my current approach to improving speed. I wonder if anybody can help me improve it so that the time waiting after selecting a new dropdown value decreases. Note that I am using a notebook with vscode and using pn.serve() to open in a browser. I am happy to create a script or use other methods if there will be a significant speed increase.

  1. Create every possible altair chart (all dropdown selection possibilities) and save them in a dictionary - this step is done in advance.
  2. Pass this dictionary into the panel function and let the widget value point to different charts within the dictionary by changing the key value.

This works, but it takes around 35 seconds to change after changing the dropdown selection.
Any ideas on how I can speed this up?

Below is chopped down code so you can see roughly what my approach consists of (I couldn’t find a way to pass the dict into the function so I resorted to using global):

global dict_of_charts
dict_of_charts = function_that_gets_all_charts()

df_tickers = ['df1', 'df2' ......]
df_ticker = pn.widgets.Select(name='Choose a dataset:', options=df_tickers)

def panel_function(df_ticker):

    return dict_of_charts[df_ticker]

# create the Panel object

dashboard = pn.Row(



1 Like

Hi @aaronr

Welcome to the community.

Could you share a minium, reproducible example including data? That would enable someone to run, debug, profile and understand What goes on.