How do I take a user click_event and use that to pull data from another source

17 Views Asked by At

So I have a chart, that when a data point is clicked on, it returns an event:

# Fetch the data from the URL and load it into a DataFrame
url = 'https://gwosc.org/eventapi/csv/GWTC/'
data = pd.read_csv(url)

#create chart
fig = px.scatter(data, x="total_mass_source", y="commonName")

fig.update_layout(
    yaxis = dict(
        tickmode = 'array',
        tickvals = np.arange(len(data)),
        ticktext = data.index.astype(str)
    ),
)

#get user input
select_event = plotly_events(fig, click_event=True,)

selected_gwc_event = [point['y'] for point in select_event]

st.write(selected_gwc_event)

Something like "GW190412",

now I want to use that to pull the relevant data from the Gravitational Wave Open Science Center.

Usually you would just input the event name to pull the gps information like in this example:

from gwosc.datasets import event_gps
gps = event_gps('GW190412')
print(gps)

but I'm not sure how to take my user click_event and have it pull the gps data, I tried just inserting "selected_gwc_event" in there but that obviously didn't work.

0

There are 0 best solutions below