import streamlit as st
import plotly.graph_objects as go
import pandas as pd
# Sample data
data = {
'Category': ['A', 'B', 'C', 'D'],
'Value1': [10, 15, 20, 25],
'Value2': [20, 25, 30, 35],
'Value3': [30, 35, 40, 45]
}
df = pd.DataFrame(data)
# Create a stacked bar chart using Plotly
fig = go.Figure(data=[
go.Bar(name='Value1', x=df['Category'], y=df['Value1'], marker_color='red'),
go.Bar(name='Value2', x=df['Category'], y=df['Value2'], marker_color='lightblue'),
go.Bar(name='Value3', x=df['Category'], y=df['Value3'], marker_color='blue')
])
# Change the bar mode to 'stack'
fig.update_layout(barmode='stack', title='Stacked Bar Chart')
# Streamlit app
st.title('Stacked Bar Chart using Plotly and Streamlit')
st.plotly_chart(fig)