3

I currently have a dashboard with a scattermapbox map that plots the movement of people across a network, and uses several callbacks to update graphs based on hoverdata, etc. The mapbox graph uses a slider (dcc.Slider) to adjust the timestep that is currently showing. I want to add a "play" button that automates the process of clicking through the different timesteps on the slider.

I had success with the same dataset and parameters creating a play button in Plotly, because there are no callbacks and the sliders are an element in the layout dictionary for the figure. However, I am unsure where to place the callback for the buttons in Dash and unsure if it should use the animate method or the relayout method.

Currently I have just created a frame for each timestep (separate from the traces encompassed in data).

4

1 回答 1

1

当谈到推进滑块时,我还没有找到一种“好的”/自然的方式来做到这一点。但是,我得到了一个使用Interval组件的解决方法。

import dash_core_components as dcc
import dash_html_components as html
import dash.dependencies
from dash.dependencies import Input, Output



app.layout = html.Div(children=[
dcc.Interval(id='auto-stepper',
            interval=1*1000, # in milliseconds
             n_intervals=0
),
dcc.Slider(
    id = "steper",
    min=1,
    max=step_num,
    value=1
)]

然后,我有一个回调:

@app.callback(
    dash.dependencies.Output('steper', 'value'),
    [dash.dependencies.Input('auto-stepper', 'n_intervals')])
def on_click(n_intervals):
    if n_intervals is None:
        return 0
    else:
        return (n_intervals+1)%step_num

这样做的最终结果是每秒触发对我的滑块的回调,并推进它。注意最后的模数以阻止它走远。

于 2018-05-03T13:26:53.053 回答