Hi,
Is there any way to select points in a chart with a command driven for example by an event from another chart (select points in chart 1, highlight them on chart 2, etc)?
Hi,
Is there any way to select points in a chart with a command driven for example by an event from another chart (select points in chart 1, highlight them on chart 2, etc)?
@datadrinkr, there is an example in this doc demonstrating how you can do this with Dash.
aha, selectedpoints is read/write, perfect.
hi, I hope this is the right spot to ask this.
I am trying to update a datatable based on the selectedData from a graph component. This works fine when I use the box or lasso tools myself, but if I try to make the selection through the selectedpoints attribute the datatable remains empty.
Is it possible to have selectedData default to the data corresponding to the selectedpoints attribute? Or else, at least default all points in the figure rather than none?
thanks
This works fine when I use the box or lasso tools myself,how? please upload your code if you can
Follow-up question here. It appears (although do correct me if I’m wrong) that when one sets the selectedata attribute, subsequent selections reset this. For instance, if I set a choropleth map with clickmode=“click+select” to show Texas and New Hampshire as selected, then try to shift+click to add other states, it clears those predefined selected points. In other words, are the selectedpoints and selectedData attributes in conflict with each other?
Minimal example:
import dash
from dash import Dash, html, dcc, Input, Output
import dash_bootstrap_components as dbc
import plotly.graph_objects as go
import json
mapdata={
'counts': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50],
'states': ['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY']
}
app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
server = app.server
def getfig():
fig = go.Figure(data=go.Choropleth(
locations=mapdata['states'],
z = mapdata['counts'],
locationmode = 'USA-states',
colorscale="Reds"
))
fig.update_layout(
clickmode='event+select',
geo_scope='usa'
)
return fig
fig=getfig()
app.layout = html.Div([
dcc.Graph(id="choropleth_map",figure=fig),
html.Button(id='submit_button', n_clicks=0, children='Submit')
])
@app.callback(
Output('choropleth_map','figure'),
Input('submit_button','n_clicks')
)
def clickbutton(button):
fig = getfig()
fig.update_traces(
selectedpoints=[6,7,8]
)
return fig
if __name__ == '__main__':
app.run_server(debug=True)
Hi @johnmulligan have you solved this? I’m stumped on the exact same problem
Hey, I’m sorry – I only saw this now, having logged in for something else after a while.
I did not figure it out, but instead just dropped the dcc.store implementation: removing alternative builds (multiselect + dcc.store didn't work) · JohnMulligan/covid_dashPy@87db8a6 · GitHub
I hope that helps!
John
@johnmulligan hi, the link to GitHub is dead. Could you please comment on how did you manage do solve this?
Thanks.
Hi @Dano, what exactly do you want to achieve?
Hi @AIMPED , I have a slider and a graph that I want to communicate with each other. I had two callbacks one with Input on slider value and output on selectedpoints of the graph, this highlighted the years I selected on the range slider (it took the interval and selected all year bars on the graph inside the interval). Then i had a second callback with input of selectedData from graph with output to the slider (where I took the min and max year selected on the graph and mapped it to the range slider value). Then I also had another callback with selectedData as input (that filtered the selected years on a map) which of course did not fire when I selected years via the slider because selectedData isnt applied when I write into selectedpoints. Also, a similiar behaviour to @ johnmulligan appeared when I tried to manually select bars on the bar graph when some where highlighted from the slider, since selectedpoints and selectData do not communicate with each other. I since switched to one-way comm. slider->graph.
Thank you for your time.