Skip to content

Add @st.cache_data to all builders, .gitignore, and live-demo badge#1

Draft
Copilot wants to merge 5 commits into
mainfrom
copilot/replace-dashboard-with-streamlit
Draft

Add @st.cache_data to all builders, .gitignore, and live-demo badge#1
Copilot wants to merge 5 commits into
mainfrom
copilot/replace-dashboard-with-streamlit

Conversation

Copilot AI commented Mar 12, 2026

Copy link
Copy Markdown

The app had no caching — every user visit and every widget interaction re-read the CSV and rebuilt all 8 charts from scratch. First-deploy load time was also a concern.

Changes

  • dashboard.py — added @st.cache_data to all 9 functions (load_data, every chart builder, and build_route_map). Results are computed once per cold start and served from cache on all subsequent interactions.
# Before
def load_data(csv_path: str = "SmartTourRoutePlanner.csv") -> pd.DataFrame:
    return pd.read_csv(csv_path)

# After
@st.cache_data
def load_data(csv_path: str = "SmartTourRoutePlanner.csv") -> pd.DataFrame:
    return pd.read_csv(csv_path)
  • README.md — added Streamlit badge and live-demo URL at the top so visitors can reach the deployed app directly.

  • .gitignore — added (was missing); excludes __pycache__/, *.pyc, .ipynb_checkpoints/, and common OS artifacts.

Original prompt

Goal

Replace the existing Dash-based dashboard.py with a Streamlit-based dashboard that includes all 7 existing Plotly charts plus the Folium geographical map from the notebook. Add deployment config for Streamlit Community Cloud.

Existing Files

  • SmartTourRoutePlan.ipynb — the original notebook
  • SmartTourRoutePlanner.csv — the dataset (500 rows, 19 columns)
  • dashboard.py — current Dash-based dashboard with 7 Plotly charts
  • travel_route_map.html — the Folium map output from the notebook

What to do

1. Rewrite dashboard.py using Streamlit

Convert the existing Dash app to Streamlit. Keep ALL 7 existing chart functions exactly as they are (same Plotly code, same titles, same colors, same parameters):

  • build_traffic_time_line — Line plot: Impact of Traffic Density on Estimated Travel Time
  • build_demand_heatmap — Density heatmap: Travel Demand (Day Type vs Season) with transport animation
  • build_budget_satisfaction_scatter — Scatter: User Budget vs Satisfaction Rating by Transport Mode
  • build_cost_sankey — Sankey: Travel Cost Flow Distribution
  • build_travel_preference_sunburst — Sunburst: Season → Transport Mode → Destination Type
  • build_transport_radar — Radar chart comparing transport modes across travel factors
  • build_traffic_violin — Violin: Traffic density distribution by day_type

Replace Dash layout (dcc.Tabs, dcc.Graph, html.Div) with Streamlit equivalents (st.tabs, st.plotly_chart, st.title, etc.).

2. Add the Folium Map Tab — EXACT code from notebook

Add a new tab called "🗺️ Route Map" with the exact Folium map from the notebook. Use streamlit-folium (st_folium) to embed it. Here is the exact map code to use:

import folium
from streamlit_folium import st_folium

city_coords = {
    "Delhi": (28.6139, 77.2090),
    "Mumbai": (19.0760, 72.8777),
    "Bangalore": (12.9716, 77.5946),
    "Chennai": (13.0827, 80.2707),
    "Kolkata": (22.5726, 88.3639),
    "Agra": (27.1767, 78.0081),
    "Goa": (15.2993, 74.1240),
    "Shimla": (31.1048, 77.1734),
    "Ooty": (11.4064, 76.6932),
    "Mahabalipuram": (12.6208, 80.1937)
}

df["start_lat"]=df["start_location"].map(lambda x: city_coords.get(x, (None, None))[0])
df["start_lon"]=df["start_location"].map(lambda x: city_coords.get(x, (None, None))[1])

df["end_lat"]=df["end_location"].map(lambda x: city_coords.get(x, (None, None))[0])
df["end_lon"]=df["end_location"].map(lambda x: city_coords.get(x, (None, None))[1])

m=folium.Map(location=[22.5, 80], zoom_start=5, tiles="cartodbpositron")

mode_colors={
    "car":"blue",
    "train":"green",
    "bike":"orange",
    "walk":"purple",
    "bus":"brown"
}

for _, row in df.iterrows():
    if pd.notnull(row["start_lat"]) and pd.notnull(row["end_lat"]):
        start=(row["start_lat"], row["start_lon"])
        end=(row["end_lat"], row["end_lon"])
        color=mode_colors.get(str(row["transport_mode"]).lower(), "black")

        folium.PolyLine(
            locations=[start, end],
            color=color,
            weight=3,
            opacity=0.8,
            tooltip=f"{row['start_location']}{row['end_location']} ({row['transport_mode']})"
        ).add_to(m)

        folium.CircleMarker(
            location=start,
            radius=row["popularity_score"] / 20,
            color="blue",
            fill=True,
            fill_opacity=0.7,
            popup=f"Start: {row['start_location']}"
        ).add_to(m)

        folium.CircleMarker(
            location=end,
            radius=row["popularity_score"] / 20,
            color="orange",
            fill=True,
            fill_opacity=0.7,
            popup=f"End: {row['end_location']}"
        ).add_to(m)

Then render with: st_folium(m, width=900, height=600)

3. Add requirements.txt

streamlit
pandas
plotly
scikit-learn
folium
streamlit-folium

4. Add .streamlit/config.toml

[theme]
primaryColor = "#4C78A8"
backgroundColor = "#FFFFFF"
secondaryBackgroundColor = "#F0F2F6"
textColor = "#262730"

[server]
headless = true
port = 8501

5. Update README.md

Add sections for:

  • Project description
  • How to run locally (pip install -r requirements.txt then streamlit run dashboard.py)
  • How to deploy on Streamlit Community Cloud
  • Description of all dashboard tabs including the map

Important

  • Do NOT delete or change the notebook or CSV file
  • The travel_route_map.html can remain as-is (it's a static export)
  • ALL 7 Plotly chart functions must produce identical output — same data processing, same colors, same titles, same layout configs
  • The Folium map must be an EXACT replica of the notebook code shown above
  • Use st.plotly_chart(fig, use_container_width=True) for all Plotly charts

The following is the prior conversation context from the user's chat exploration (may be truncated):

Assistant: Both projects are live! 🎉 I've analyzed everything. Here's what I found:

🧠 Project 1: SwipeTCHA

  • Beha...

This pull request was created from Copilot chat.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

…deployment config

Co-authored-by: budugameghraj <178402503+budugameghraj@users.noreply.github.com>
Copilot AI changed the title [WIP] Replace Dash-based dashboard with Streamlit version Replace Dash dashboard with Streamlit + add Folium India route map tab Mar 12, 2026
@budugameghraj

Copy link
Copy Markdown
Owner

streamlit

Co-authored-by: budugameghraj <178402503+budugameghraj@users.noreply.github.com>
Copilot AI changed the title Replace Dash dashboard with Streamlit + add Folium India route map tab Add Streamlit live demo badge and link to README Mar 12, 2026
Copilot AI and others added 2 commits March 12, 2026 18:32
Co-authored-by: budugameghraj <178402503+budugameghraj@users.noreply.github.com>
Co-authored-by: budugameghraj <178402503+budugameghraj@users.noreply.github.com>
Copilot AI changed the title Add Streamlit live demo badge and link to README Add @st.cache_data to all builders, .gitignore, and live-demo badge Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants