Plotly Slider - how to change data values?

Hello Community,

With the support of @empet I was able to create nice choropleth plots to visualize runoffs in german communities during the flooding in last summer.
My next step would be to add a slider in order to scroll through the most interesting 48 hours to show the water runoff within the communities.

I have found only the possibility to update values by creating 48 traces and to switch 47 to unvisible and the actual one to visible. But creating 48 traces with 2000 shapes, names and values would lead to unnecessary large html files whereas only the values z (for coloring and hover-text) would need different values.

Therefore, I would prefer a possibility to update only the z values of the one choropleth trace.

Until now, I have not found any example in the web, where only e.g. y-values of a scatterplot are updated when changing the slider position (without making N-1 traces invisible and 1 visible)

Does one know, if and in the case of yes, how z values (of choropleth) or y values (of scatter traces) can be updated when updating the slider (without defining plenties of traces with redundant data for x coordinates for scatterplots or geojsons for choropleth)?

Thanks for any hints!

using PlotlyJS
using DataFrames

df = DataFrame(iso=["8","7","9","2","1","4","3","6","5"], 
               names=["Vorarlberg", "Tirol", "Wien", "Kärnten","Burgenland",
for k in 1:48
   df[!, "Wert$k"] = rand(9) 

choropl = choroplethmapbox(geojson = ""*
                           featureidkey = "properties.iso",
                           locations = df.iso,
                           zmin=0, zmax=1, 
                           text=df.names, colorscale="Viridis",
                           marker=attr(opacity=0.85, line=attr(width=0.5,color="white")))

layout = Layout(mapbox = attr(center=attr(lon =13.5,lat=47.76),
                              zoom=5.67, style="open-street-map"),
                              currentvalue=attr(prefix= "Nach ", suffix= " Stunde"), 
                                          method = "restyle",
                                          args = [attr(z=[df[!,"Wert$k"]])]) for k in 1:48])]
pl= Plot(choropl, layout)

In each slider step are updated z-values in the choroplethmapbox, as z= [df[!, "Wert$k"]], NOT z=df[!, "Wert$k"]!!!
That’s because we can pass to Plot a vector of traces, not just a single trace.
z= [df[!, "Wert$k"]] means that here is updated z from the first trace in the vector of traces.
Similarly are updated x, y values in different trace types.

But if your plot contains two traces, for example, and in each step we want to update y-values in both traces, then the corresponding arg in the slider steps will be defined as:

args = [attr(y=[[2,5,3,4], [7, 1, 2, 5]])]
1 Like

Thank you @empet for this well working solution!