I’m trying to implement the very same feature that hovering on one graph results in a separate plot as on Part 4. Interactive Graphing and Crossfiltering | Dash for Python Documentation | Plotly
However, as the example is rather extend I’m not sure whether it’s correct what I did and/or what is not.
So far, I have:
df2 = all_df.melt(id_vars=['Device','time', 'Path'], value_vars=['V+','V-','I_A', 'I_fil'])
df2['path'] = df2['Path']
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, title='Dashboard', external_stylesheets=external_stylesheets)
colors = {
'background': '#000000',
'text': '#f3ff00'
}
app.layout = html.Div(
children = [
html.Div([
html.H4('Dauertest'),
html.Div(children = ""),
dcc.Graph(id = 'General'
, figure={}
),
dcc.RadioItems(
id="signals",
options = ['V+', 'V-', 'I_A', 'I_fil'],
value = 'V+',
inline=True
),
dcc.Graph(id = 'Zoomed'
),
html.Br(),
]),
])
@app.callback(
Output("General", "figure"),
Input("signals", "value")
)
def update_scatter_chart(signals):
df3 = df2.query('variable==@signals').groupby('path').first()
fig_general = px.scatter(df3
, x = "time"
, y = 'value'
, custom_data = ['Path']
, color = 'Device'
, symbol = 'variable'
, hover_name = "Device"
, opacity = 0.6
, template = 'plotly_dark'
, marginal_y = "rug"
)
fig_general.update_layout(
transition_duration = 500
, autosize = True
, height = 700
, hovermode = 'closest'
)
fig_general.update_traces(marker = dict(
size = 14
)
)
return fig_general
def update_zoom_chart(df5):
fig_zoom = px.scatter(df5
, x = "time"
, y = 'value'
, color = 'Device'
, symbol = 'variable'
, hover_name = "Device"
, opacity = 0.6
, template = 'plotly_dark'
)
fig_zoom.update_layout(
transition_duration = 500
, autosize = True
, height = 500
)
return fig_zoom
@app.callback(
Output("Zoomed", "figure"),
Input('General', 'hoverData')
)
def update_hover(hoverData):
path = hoverData['points'][0]['customdata']
df5 = df2[df2['Path' == path]]
return update_zoom_chart(df5)
At the moment I receive the error:
in update_hover
path = hoverData['points'][0]['customdata']
TypeError: 'NoneType' object is not subscriptable
But according to the linked example I do not see the difference?