Spaces:
Sleeping
Sleeping
File size: 3,046 Bytes
e7d47b3 5806592 e7d47b3 5ce6155 e7d47b3 5806592 e7d47b3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File: streamlit_dashboard.py
import streamlit as st
import requests
import pandas as pd
import plotly.express as px
st.set_page_config(
page_title="Data Visualizer - Rajeev",
page_icon="π", # Can also use emoji
)
BASE_URL = "https://splashdatavisualize-production.up.railway.app/api/visualizations"
st.title("π Sales Visualization Dashboard")
st.markdown("Use the sidebar to choose a visualization.")
chart_type = st.sidebar.selectbox("Select a Chart", [
"Sales by Country",
"Sales by Category",
"Share by Country",
"Share by Category",
"Geo Sales",
"Grouped Country & Category",
"Stacked Country & Category"
])
# 1. Sales by Country
if chart_type == "Sales by Country":
data = requests.get(f"{BASE_URL}/sales-by-country").json()
df = pd.DataFrame(data.items(), columns=["Country", "Sales"])
st.plotly_chart(px.bar(df, x="Country", y="Sales", title="Sales by Country"))
# 2. Sales by Category
elif chart_type == "Sales by Category":
data = requests.get(f"{BASE_URL}/sales-by-category").json()
df = pd.DataFrame(data.items(), columns=["Category", "Sales"])
st.plotly_chart(px.bar(df, x="Category", y="Sales", title="Sales by Category"))
# 3. Share by Country (Pie Chart)
elif chart_type == "Share by Country":
data = requests.get(f"{BASE_URL}/share-by-country").json()
df = pd.DataFrame(data.items(), columns=["Country", "Share %"])
st.plotly_chart(px.pie(df, names="Country", values="Share %", title="Share by Country"))
# 4. Share by Category (Pie Chart)
elif chart_type == "Share by Category":
data = requests.get(f"{BASE_URL}/share-by-category").json()
df = pd.DataFrame(data.items(), columns=["Category", "Share %"])
st.plotly_chart(px.pie(df, names="Category", values="Share %", title="Share by Category"))
# 5. Geo Sales
elif chart_type == "Geo Sales":
data = requests.get(f"{BASE_URL}/geo-sales").json()
df = pd.DataFrame(data)
st.plotly_chart(px.choropleth(df, locations="country", locationmode="country names",
color="value", title="Geo Sales by Country", color_continuous_scale="Blues"))
# 6. Grouped Country & Category
elif chart_type == "Grouped Country & Category":
data = requests.get(f"{BASE_URL}/grouped-country-category").json()
df = pd.DataFrame(data).T.reset_index().rename(columns={"index": "Country"})
df = df.melt(id_vars="Country", var_name="Category", value_name="Sales")
st.plotly_chart(px.bar(df, x="Country", y="Sales", color="Category", barmode="group",
title="Grouped Sales by Country and Category"))
# 7. Stacked Country & Category
elif chart_type == "Stacked Country & Category":
data = requests.get(f"{BASE_URL}/stacked-country-category").json()
df = pd.DataFrame(data)
df = df.melt(id_vars="country", var_name="Category", value_name="Sales")
st.plotly_chart(px.bar(df, x="country", y="Sales", color="Category", barmode="stack",
title="Stacked Sales by Country and Category"))
|