have a plotly graph in line mode with the ability to switch to box select in the modeBarButtons
To upload files, please first save the app
import streamlit as st
import plotly.express as px
import numpy as np
import pandas as pd
# Generate sample data
np.random.seed(42)
df = pd.DataFrame({
'x': range(100),
'y': np.random.randn(100).cumsum()
})
# Create line plot with custom mode bar
fig = px.line(df, x='x', y='y', title='Interactive Line Plot with Box Select')
# Update layout to include the box select button in the mode bar
fig.update_layout(
showlegend=True,
hovermode='x unified',
# Add dragmode and modeBarButtons configuration
dragmode='pan',
modebar=dict(
add=['select2d'] # This adds the box select button
)
)
# Display the plot
st.plotly_chart(fig, use_container_width=True, on_select='rerun')
# If there's a selection, show the selected points
if st.session_state.get('plotly_selected_data'):
st.write("Selected data points:", st.session_state.plotly_selected_data)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?