Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,66 +1,83 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
-
import plotly.express as px
|
4 |
import plotly.graph_objects as go
|
5 |
|
6 |
# Title of the App
|
7 |
-
st.title("Excel
|
8 |
|
9 |
-
#
|
10 |
uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx", "xls"])
|
11 |
|
12 |
if uploaded_file:
|
13 |
-
# Read Excel file
|
14 |
try:
|
|
|
15 |
df = pd.read_excel(uploaded_file)
|
|
|
|
|
16 |
st.write("Data Preview:")
|
17 |
st.dataframe(df)
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
fig = px.line(df, x=x_axis, y=y_axis)
|
36 |
-
st.plotly_chart(fig)
|
37 |
|
38 |
-
|
39 |
-
fig
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
fig = go.Figure()
|
44 |
-
fig.add_trace(go.Scatter(x=df[x_axis], y=df[y_axis[0]], mode='lines', name=y_axis[0]))
|
45 |
-
fig.add_trace(go.Scatter(x=df[x_axis], y=df[y_axis[1]], mode='lines', name=y_axis[1], yaxis="y2"))
|
46 |
-
|
47 |
-
# Add a secondary y-axis
|
48 |
fig.update_layout(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
yaxis2=dict(
|
50 |
-
title=
|
51 |
-
|
52 |
-
|
|
|
|
|
53 |
),
|
54 |
-
|
|
|
|
|
55 |
)
|
|
|
|
|
56 |
st.plotly_chart(fig)
|
57 |
-
else:
|
58 |
-
st.warning("Please select appropriate columns and graph type.")
|
59 |
except Exception as e:
|
60 |
-
st.error(f"Error
|
61 |
else:
|
62 |
st.info("Please upload an Excel file to get started.")
|
63 |
|
64 |
-
#
|
65 |
st.write("---")
|
66 |
st.write("Developed using [Streamlit](https://streamlit.io) and [Hugging Face Spaces](https://huggingface.co/spaces).")
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
|
|
3 |
import plotly.graph_objects as go
|
4 |
|
5 |
# Title of the App
|
6 |
+
st.title("Excel Data Visualization with Dual Y-Axis")
|
7 |
|
8 |
+
# Upload Section
|
9 |
uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx", "xls"])
|
10 |
|
11 |
if uploaded_file:
|
|
|
12 |
try:
|
13 |
+
# Read the Excel file into a DataFrame
|
14 |
df = pd.read_excel(uploaded_file)
|
15 |
+
|
16 |
+
# Preview the uploaded data
|
17 |
st.write("Data Preview:")
|
18 |
st.dataframe(df)
|
19 |
|
20 |
+
# Ensure required columns are present
|
21 |
+
required_columns = ["Description", "Oct'24", "Nov'24", "Dec/(Inc)"]
|
22 |
+
if not all(column in df.columns for column in required_columns):
|
23 |
+
st.error(f"The uploaded file must contain the following columns: {', '.join(required_columns)}")
|
24 |
+
else:
|
25 |
+
# Plot the Graph
|
26 |
+
fig = go.Figure()
|
27 |
|
28 |
+
# Add Bar Traces for Oct'24 and Nov'24
|
29 |
+
fig.add_trace(go.Bar(
|
30 |
+
x=df["Description"],
|
31 |
+
y=df["Oct'24"],
|
32 |
+
name="Oct'24",
|
33 |
+
marker_color='blue'
|
34 |
+
))
|
35 |
|
36 |
+
fig.add_trace(go.Bar(
|
37 |
+
x=df["Description"],
|
38 |
+
y=df["Nov'24"],
|
39 |
+
name="Nov'24",
|
40 |
+
marker_color='green'
|
41 |
+
))
|
|
|
|
|
42 |
|
43 |
+
# Add Line Trace for Dec/(Inc) on Secondary Y-axis
|
44 |
+
fig.add_trace(go.Scatter(
|
45 |
+
x=df["Description"],
|
46 |
+
y=df["Dec/(Inc)"],
|
47 |
+
name="Dec/(Inc)",
|
48 |
+
mode="lines+markers",
|
49 |
+
marker=dict(color='red'),
|
50 |
+
yaxis="y2"
|
51 |
+
))
|
52 |
|
53 |
+
# Update Layout for Dual Y-axis
|
|
|
|
|
|
|
|
|
|
|
54 |
fig.update_layout(
|
55 |
+
title="Dual Axis Chart",
|
56 |
+
xaxis=dict(title="Description"),
|
57 |
+
yaxis=dict(
|
58 |
+
title="Values (Oct'24 and Nov'24)",
|
59 |
+
titlefont=dict(color="blue"),
|
60 |
+
tickfont=dict(color="blue"),
|
61 |
+
),
|
62 |
yaxis2=dict(
|
63 |
+
title="Dec/(Inc)",
|
64 |
+
titlefont=dict(color="red"),
|
65 |
+
tickfont=dict(color="red"),
|
66 |
+
overlaying="y",
|
67 |
+
side="right"
|
68 |
),
|
69 |
+
barmode="group",
|
70 |
+
legend=dict(x=0.5, y=1.2, orientation="h"),
|
71 |
+
template="plotly_white"
|
72 |
)
|
73 |
+
|
74 |
+
# Render the Plot
|
75 |
st.plotly_chart(fig)
|
|
|
|
|
76 |
except Exception as e:
|
77 |
+
st.error(f"Error processing the file: {e}")
|
78 |
else:
|
79 |
st.info("Please upload an Excel file to get started.")
|
80 |
|
81 |
+
# Footer
|
82 |
st.write("---")
|
83 |
st.write("Developed using [Streamlit](https://streamlit.io) and [Hugging Face Spaces](https://huggingface.co/spaces).")
|