generated from dataforgoodfr/d4g-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |