# 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"))