Skip to content

Commit

Permalink
Demo dashboard dash vs streamlit
Browse files Browse the repository at this point in the history
  • Loading branch information
Qloeb committed Jun 24, 2024
1 parent fa5b9c6 commit 9d5eedd
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Dashboards/demo_dash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from dash import Dash, html, dcc, callback, Output, Input
import plotly.express as px
import pandas as pd

# Source : https://discuss.streamlit.io/t/develop-a-dashboard-app-with-streamlit-using-plotly/37148/4
# Dash version
# run with : python Dashboard/demo_dash.py

# Load data function
def load_data():
return pd.read_csv("https://people.sc.fsu.edu/~jburkardt/data/csv/airtravel.csv")

# Initialize Dash app
app = Dash(__name__)

# Load data
df = load_data()

# Define app layout with a hidden input
app.layout = html.Div([
html.H1("Air Travel Time Series Plot", style={'textAlign': 'center'}),
html.Div("This chart shows the number of air passengers traveled in each month from 1949 to 1960", style={'textAlign': 'center'}),
dcc.Graph(id='air-travel-graph'),
html.Div(id='dummy-div', style={'display': 'none'}) # Hidden div acting as a placeholder
])


# Define callback to update graph
@app.callback(
Output('air-travel-graph', 'figure'),
Input('dummy-div', 'children') # Use the hidden div as input
)
def update_graph(value):
fig = px.line(df, x="Month", y=df.columns[1:], title="Air Passenger Travel")
return fig


# Run the app
if __name__ == '__main__':
app.run_server(debug=True)
20 changes: 20 additions & 0 deletions Dashboards/demo_streamlit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import streamlit as st
import pandas as pd
import plotly.express as px

# Source : https://discuss.streamlit.io/t/develop-a-dashboard-app-with-streamlit-using-plotly/37148/4
# run with : streamlit run Dashboard/demo_streamlit.py

def load_data():
return pd.read_csv("https://people.sc.fsu.edu/~jburkardt/data/csv/airtravel.csv")

# Load data
df = load_data()

# Display some information
st.title("Air Travel Time Series Plot")
st.write("This chart shows the number of air passenger traveled in each month from 1949 to 1960")

# Plotly figure
fig = px.line(df, x="Month", y=df.columns[1:], title="Air Passenger Travel")
st.plotly_chart(fig)

0 comments on commit 9d5eedd

Please sign in to comment.