How do I make interactive buttons in plotly, that will change the chart and send their interaction to streamlit?
To upload files, please first save the app
import streamlit as st
import plotly.express as px
import pandas as pd
# Sample Data
df = pd.DataFrame({
'X': ['A', 'B', 'C', 'D'],
'Y1': [4, 1, 3, 5],
'Y2': [1, 4, 2, 3]
})
# Streamlit App
st.title('Interactive Plotly Chart with Buttons')
# Function to create chart
def create_chart(y_col):
fig = px.bar(df, x='X', y=y_col, title=f'Bar Chart for {y_col}')
st.plotly_chart(fig)
# Button for different Y-axis data
if st.button('Show Y1 Data'):
create_chart('Y1')
elif st.button('Show Y2 Data'):
create_chart('Y2')
else:
create_chart('Y1') # Default chart
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?