Skip to content

Using plotly-resampler with dashapp? #56

@k-a-mendoza

Description

@k-a-mendoza

I'm having some issues when rendering this figure with dashapp.

Firstly, I make a dashapp with the following controls:

controls = [
            dcc.Graph(
                id='uptime-graph',
               ''' some additional styling"""
                }
            ),
            dcc.Graph(
                id='timeseries-graph',
                figure={
                    'data': []
                    
                }
            )
        ]

I'm using an uptime graph to select specific trace segments I want to look at. then, I update 'timeseries-graph' with a callback upon selection within the uptime graph:

def update_timeseries(relayoutData):
    if new_coords is None or 'autosize' in new_coords.keys() or 'xaxis.autorange' \
        in new_coords.keys():
            return None
    start = new_coords['xaxis.range[0]']
    end   = new_coords['xaxis.range[1]']
    dict_frame = self.model.get_timeseries(start,end)
    n_titles, plotting_dict = self._restructure_data(dict_frame)

    fig = FigureResampler(
                        make_subplots(
                            rows=len(plotting_dict.keys()),
                            cols=1,
                            row_titles=n_titles,
                            vertical_spacing=0.001,
                            shared_xaxes=True),
                            default_n_shown_samples=5_000,
                                verbose=False,
                    )
    fig['layout'].update(height=1700)
    row_iterator = 1
    has_legend = {'ex':False,'ey':False,'hx':False,'hy':False,'hz':False}
    for station_key in plotting_dict.keys():
        for trace_data in plotting_dict[station_key]:
            color = self._get_trace_color(station_key)
            name, showlegend =self._legend_name_parser(has_legend,station_key)
            fig.add_trace(go.Scattergl(name=name, showlegend=showlegend,connectgaps=False,
                                                   line={'color':color,'dash':'solid'}), 
                            hf_x=trace_data.time, hf_y=trace_data['value'],row=row_iterator,col=1)
        row_iterator+=1
    print('updated timeseries figure')
    fig.show_dash(mode='inline')
    return fig


@dashapp.callback(
    Output('timeseries-graph', 'figure'),
    Input('uptime-graph', 'relayoutData'))
def uptime_data_select(relayoutData):
    fig = controller.update_timeseries_daterange(relayoutData)
    return fig

It kinda works, then begins to spit the same error every four seconds, preventing any further interaction with the webapp


Traceback (most recent call last):
  File "/Users/.../miniconda3/envs/mtpytest/lib/python3.9/site-packages/flask/app.py", line 2077, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users.../miniconda3/envs/mtpytest/lib/python3.9/site-packages/flask/app.py", line 1525, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/.../miniconda3/envs/mtpytest/lib/python3.9/site-packages/flask/app.py", line 1523, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/.../miniconda3/envs/mtpytest/lib/python3.9/site-packages/flask/app.py", line 1509, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/Users/.../miniconda3/envs/mtpytest/lib/python3.9/site-packages/dash/dash.py", line 1382, in dispatch
    raise KeyError(msg.format(output)) from missing_callback_function
KeyError: "Callback function not found for output 'timeseries-graph.figure', perhaps you forgot to prepend the '@'?"
2022-05-11T15:10:10 [line 1455] local_app.log_exception - ERROR: Exception on /_dash-update-component [POST]
Traceback (most recent call last):
  File "/Users/kevinmendoza/miniconda3/envs/mtpytest/lib/python3.9/site-packages/dash/dash.py", line 1344, in dispatch
    cb = self.callback_map[output]
KeyError: 'timeseries-graph.figure'

I suppose its possible i'm not using it correctly, but if I am, there appears to be an error with resampling hooking back into the graph.

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationquestionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions