chart_generator
To upload files, please first save the app
import streamlit as st
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
import numpy as np
st.set_page_config(page_title="Chart Generator", layout="wide")
st.title("📊 Interactive Chart Generator")
# Sidebar for data generation
st.sidebar.header("Data Settings")
num_points = st.sidebar.slider("Number of data points", 10, 1000, 100)
noise_level = st.sidebar.slider("Noise level", 0.0, 1.0, 0.2)
# Generate sample data
x = np.linspace(0, 10, num_points)
y1 = np.sin(x) + np.random.normal(0, noise_level, num_points)
y2 = np.cos(x) + np.random.normal(0, noise_level, num_points)
y3 = x**2/30 + np.random.normal(0, noise_level, num_points)
df = pd.DataFrame({
'x': x,
'Sine': y1,
'Cosine': y2,
'Quadratic': y3
})
# Main content
col1, col2 = st.columns([1, 2])
with col1:
st.subheader("Chart Settings")
chart_type = st.selectbox(
"Select chart type",
["Line", "Scatter", "Bar", "Area", "Box Plot"]
)
y_columns = st.multiselect(
"Select data series to plot",
['Sine', 'Cosine', 'Quadratic'],
default=['Sine']
)
color_theme = st.selectbox(
"Color theme",
["plotly", "plotly_dark", "seaborn", "ggplot2"]
)
show_markers = st.checkbox("Show markers", value=True)
with col2:
st.subheader("Generated Chart")
if chart_type == "Line":
fig = px.line(df, x='x', y=y_columns, template=color_theme)
if show_markers:
fig.update_traces(mode='lines+markers')
elif chart_type == "Scatter":
fig = px.scatter(df, x='x', y=y_columns, template=color_theme)
elif chart_type == "Bar":
fig = px.bar(df, x='x', y=y_columns, template=color_theme)
elif chart_type == "Area":
fig = px.area(df, x='x', y=y_columns, template=color_theme)
elif chart_type == "Box Plot":
fig = px.box(df[y_columns], template=color_theme)
fig.update_layout(
title="Interactive Data Visualization",
xaxis_title="X Axis",
yaxis_title="Y Axis",
height=600
)
st.plotly_chart(fig, use_container_width=True)
# Display raw data
if st.checkbox("Show raw data"):
st.dataframe(df)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?