Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updatemenus key not supported? #98

Closed
iuliancioarca opened this issue Apr 23, 2021 · 1 comment
Closed

updatemenus key not supported? #98

iuliancioarca opened this issue Apr 23, 2021 · 1 comment

Comments

@iuliancioarca
Copy link

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)
`

@waralex
Copy link
Collaborator

waralex commented Oct 23, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants