updatemenus key not supported?
iuliancioarca opened this issue · comments
I would like to create animations with Dash but I'm stuck at displaying the simple Play button in the Layout. Is the "updatemenus" key not available in the Julia version?
`
app = dash()
app.layout = html_div() do
html_div(html_button("Plot", id="b1")),
html_div(dcc_graph(id="g1"))
end
callback!(
app,
Output("g1", "figure"),
Input("b1", "n_clicks")
) do nc
tall = 0:1e-3:1
yall = randn(length(tall))
data = scatter(;x=tall,
y=yall,
mode="lines")
layout = Layout(;
#yaxis_range = [-100, 100],
xaxis_type = "linear",
xaxis_title = "t [s]",
yaxis_title = "y []",
title="Primary Graph",
legend_x = 1,
legend_y = 1,
hovermode = "closest",
hoverlabel=(font=(size=10,),font_family="Rockwell"),
transition_duration = 5,
updatemenus=[(visible=true, type="buttons", buttons=(label="Play", method="animate", args=[nothing]))]
)
return Plot(
data,
layout,
[frame(name="a", data=data)]
);
end
run_server(app, "0.0.0.0", 8080, debug=true)
`
buttons
property of updatemenus
must be an array. As well as data
in frame
. See, for example, this docs: https://plotly.com/python/animations/
A working example of what you wanted here:
using Dash, Printf, PlotlyJS
app = dash()
app.layout = html_div() do
html_div(html_button("Plot", id="b1")),
html_div(dcc_graph(id="g1"))
end
callback!(
app,
Output("g1", "figure"),
Input("b1", "n_clicks")
) do nc
tall = 0:1e-3:1
frames = PlotlyFrame[]
yall = randn(length(tall))
data = [scatter(;x=tall,
y=yall,
mode="lines")]
for i in 1:5
yall = randn(length(tall))
push!(frames, frame(name="a$(i)", data =
[scatter(;x=tall,
y=yall,
mode="lines")]
))
end
layout = Layout(;
#yaxis_range = [-100, 100],
xaxis_type = "linear",
xaxis_title = "t [s]",
yaxis_title = "y []",
title="Primary Graph",
legend_x = 1,
legend_y = 1,
hovermode = "closest",
hoverlabel=(font=(size=10,),font_family="Rockwell"),
transition_duration = 5,
updatemenus=[
( visible=true,
type="buttons",
buttons=[(label="Play", method="animate", args=[nothing])]
)
]
)
return Plot(
data,
layout,
frames
);
end
run_server(app, "0.0.0.0", 8080, debug=true)