Is it possible to somehow add the option to enable/disable the popups in plotly but lively? I mean, I don’t want to remove them from the plot, but I would like to be able to enable/disable them with some kind of check box like I have drawn below:
Is this possible?
If an example is needed, anyone from this link can be used, e.g.:
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", symbol="species")
fig.show()
If there is a global setting that controls this for all the plots, that would be nice.
hoatran
November 2, 2022, 11:22am
2
I think maybe you need to use callback
for this one:
import pandas as pd
import numpy as np
import plotly.express as px
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output
import dash_bootstrap_components as dbc
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", symbol="species")
app = dash.Dash(__name__,external_stylesheets=[dbc.themes.LUX])
app.layout = html.Div([
dbc.Row([
dbc.Col([
dbc.RadioItems(id='check_list',
options=[
{'label': 'pop_up', 'value': 'pop_up'},
{'label': 'no_pop_up', 'value': 'no_pop_up'}
],
value='pop_up',
inline=True)
],width={'size':6,"offset":0,'order':1}),
]),
dbc.Row([
dbc.Col([
dcc.Graph(id='graph',figure=fig)
])
])
])
@app.callback(Output('graph','figure'),
[Input('check_list','value')])
def update_graphs(check_list):
if check_list == 'pop_up':
fig.update_layout(hovermode='closest')
if check_list == 'no_pop_up':
fig.update_layout(hovermode=False)
return fig
if __name__ == "__main__":
app.run_server(debug=False,port=1117)
So my idea is update layout based on your selection. I tried with dbc.Checklist
but it not worked so I used dbc.RadioItems
in this case.