Summary
Hi All,
I am trying to crop data using a plotly graph to select snippets and analyze. Having a lot of trouble getting any info from the selected regions of the graph. Any thoughts?
Steps to reproduce
Code snippet:
fig1 = go.Figure()
fig1.add_trace(go.Scatter(y=boat_speed,
fill=None,
mode='lines',
line_color = 'blue',
name = 'boat speed'))
fig1.update_layout(
dragmode='select',
selectdirection='h')
# Retrieve selected data points
selected_points = fig1.data[0].selectedpoints
if selected_points:
# Extract x values of selected points
selected_x_values = [fig1.data[0].x[i] for i in selected_points]
# Compute the minimum and maximum x values
min_x = min(selected_x_values)
max_x = max(selected_x_values)
st.write("Selected x values:")
st.write(selected_x_values)
st.write("Minimum x value:")
st.write(min_x)
st.write("Maximum x value:")
st.write(max_x)
else:
st.write("No points selected.")
st.plotly_chart(fig1)
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
Explain what you expect to happen when you run the code above.
Actual behavior:
Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.
Debug info
- Streamlit version: (get it with
$ streamlit version
) - Python version: (get it with
$ python --version
) - Using Conda? PipEnv? PyEnv? Pex?
- OS version:
- Browser version:
Requirements file
Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.
Links
- Link to your GitHub repo:
- Link to your deployed app:
Additional information
If needed, add any other context about the problem here.