-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial commit #160
base: main
Are you sure you want to change the base?
initial commit #160
Conversation
Thanks for submitting this app! As Adam mentioned in issue 159, the CSS in this app is very good and it's a great example for people who are not using the Dash Bootstrap Components library. Since you are only using one dbc component, let's remove the dbc library from this example and change the Note that when using CSS in the Is there a reason you are using two single date pickers instead of the |
examples/datepicker-plots.py
Outdated
dcc.Dropdown( | ||
id='datepicker-plots-x-dropdown', | ||
options=[ | ||
{'label': 'Select a plot', 'value': ''}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to remove the "select a plot" option and include clearable=False
examples/datepicker-plots.py
Outdated
) | ||
def update_graph(n_clicks, plot_type, start_date, end_date): | ||
if not plot_type: | ||
return [], 'Please select a plot type!' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary if clearable=False
in the dropdown
examples/datepicker-plots.py
Outdated
mask = (df['date'] >= start_date) & (df['date'] <= end_date) | ||
filtered_df = df.loc[mask] | ||
|
||
time.sleep(0.25) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to increase this to at least 1 second and add a comment that this is to simulate a longer running callback
Thanks for the feedback!
Will check and update.
Best,
Nidhi
…On Tue, Jul 9, 2024 at 2:40 PM Ann Marie Ward ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In examples/datepicker-plots.py
<#160 (comment)>
:
> +import pandas as pd
+from dash import Dash, dcc, html, Input, Output, State
+import plotly.express as px
+import dash_bootstrap_components as dbc
+import time
+
+df = px.data.stocks()
+df['date'] = pd.to_datetime(df['date'])
+app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
+
+app.layout = html.Div([
+ html.Label('Plot Type', style={'margin-bottom': '5px', 'font-weight': 'bold'}),
+ dcc.Dropdown(
+ id='datepicker-plots-x-dropdown',
+ options=[
+ {'label': 'Select a plot', 'value': ''},
It's better to remove the "select a plot" option and include
clearable=False
<https://dash.plotly.com/dash-core-components/dropdown#dropdown-clear>
------------------------------
In examples/datepicker-plots.py
<#160 (comment)>
:
> + type="circle",
+ children=[html.Div(id='datepicker-plots-x-graph', children=[], style={'margin-top': '20px'})],
+ ),
+])
+
***@***.***(
+ Output('datepicker-plots-x-graph', 'children'),
+ Output('datepicker-plots-x-error-msg', 'children'),
+ Input('datepicker-plots-x-submit', 'n_clicks'),
+ State('datepicker-plots-x-dropdown', 'value'),
+ State('datepicker-plots-x-start-date', 'date'),
+ State('datepicker-plots-x-end-date', 'date')
+)
+def update_graph(n_clicks, plot_type, start_date, end_date):
+ if not plot_type:
+ return [], 'Please select a plot type!'
not necessary if clearable=False in the dropdown
------------------------------
In examples/datepicker-plots.py
<#160 (comment)>
:
> + State('datepicker-plots-x-end-date', 'date')
+)
+def update_graph(n_clicks, plot_type, start_date, end_date):
+ if not plot_type:
+ return [], 'Please select a plot type!'
+ if not start_date:
+ return [], 'Please select a start date!'
+ if not end_date:
+ return [], 'Please select an end date!'
+ if end_date <= start_date:
+ return [], 'End date should be greater than start date!'
+
+ mask = (df['date'] >= start_date) & (df['date'] <= end_date)
+ filtered_df = df.loc[mask]
+
+ time.sleep(0.25)
It would be better to increase this to at least 1 second and add a comment
that this is to simulate a longer running callback
—
Reply to this email directly, view it on GitHub
<#160 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMQIM4DCDWWJ5OT53KCOOVDZLQVBPAVCNFSM6AAAAABKSBEM4WVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDCNRXGA4TEMBTGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
2) Removed dbc component and replaced it with html. 3) Set clearable=False in the dropdown and cleaned up relevant code for select a plot type. 4) Increased sleep time duration from 0.25 to 1 s to simulate longer running callback.
Hi,
I have made the changes. Please check and let me know.
1) Fixed errors on the console.
2) Removed dbc component and replaced it with html.
3) Set clearable=False in the dropdown and cleaned up relevant code for
select a plot type.
4) Increased sleep time duration from 0.25 to 1 s to simulate longer
running callback.
There is no specific reason to use 2 date pickers instead of 1 single date
picker range. It just looked better to have it in the UI, hence kept it.
Let me know if this works!
Best,
Nidhi
…On Tue, Jul 9, 2024 at 2:45 PM Nidhi Kamath ***@***.***> wrote:
Thanks for the feedback!
Will check and update.
Best,
Nidhi
On Tue, Jul 9, 2024 at 2:40 PM Ann Marie Ward ***@***.***>
wrote:
> ***@***.**** commented on this pull request.
> ------------------------------
>
> In examples/datepicker-plots.py
> <#160 (comment)>
> :
>
> > +import pandas as pd
> +from dash import Dash, dcc, html, Input, Output, State
> +import plotly.express as px
> +import dash_bootstrap_components as dbc
> +import time
> +
> +df = px.data.stocks()
> +df['date'] = pd.to_datetime(df['date'])
> +app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
> +
> +app.layout = html.Div([
> + html.Label('Plot Type', style={'margin-bottom': '5px', 'font-weight': 'bold'}),
> + dcc.Dropdown(
> + id='datepicker-plots-x-dropdown',
> + options=[
> + {'label': 'Select a plot', 'value': ''},
>
> It's better to remove the "select a plot" option and include
> clearable=False
> <https://dash.plotly.com/dash-core-components/dropdown#dropdown-clear>
> ------------------------------
>
> In examples/datepicker-plots.py
> <#160 (comment)>
> :
>
> > + type="circle",
> + children=[html.Div(id='datepicker-plots-x-graph', children=[], style={'margin-top': '20px'})],
> + ),
> +])
> +
> ***@***.***(
> + Output('datepicker-plots-x-graph', 'children'),
> + Output('datepicker-plots-x-error-msg', 'children'),
> + Input('datepicker-plots-x-submit', 'n_clicks'),
> + State('datepicker-plots-x-dropdown', 'value'),
> + State('datepicker-plots-x-start-date', 'date'),
> + State('datepicker-plots-x-end-date', 'date')
> +)
> +def update_graph(n_clicks, plot_type, start_date, end_date):
> + if not plot_type:
> + return [], 'Please select a plot type!'
>
> not necessary if clearable=False in the dropdown
> ------------------------------
>
> In examples/datepicker-plots.py
> <#160 (comment)>
> :
>
> > + State('datepicker-plots-x-end-date', 'date')
> +)
> +def update_graph(n_clicks, plot_type, start_date, end_date):
> + if not plot_type:
> + return [], 'Please select a plot type!'
> + if not start_date:
> + return [], 'Please select a start date!'
> + if not end_date:
> + return [], 'Please select an end date!'
> + if end_date <= start_date:
> + return [], 'End date should be greater than start date!'
> +
> + mask = (df['date'] >= start_date) & (df['date'] <= end_date)
> + filtered_df = df.loc[mask]
> +
> + time.sleep(0.25)
>
> It would be better to increase this to at least 1 second and add a
> comment that this is to simulate a longer running callback
>
> —
> Reply to this email directly, view it on GitHub
> <#160 (review)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AMQIM4DCDWWJ5OT53KCOOVDZLQVBPAVCNFSM6AAAAABKSBEM4WVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDCNRXGA4TEMBTGA>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
Thanks for doing the update 🙂 I see you removed the If you would like to continue to use Bootstrap, then I recommend that you keep the For exampe:
You might find this site helpful - it has more info on the utility classes https://dashcheatsheet.pythonanywhere.com/ In this example note that there is only one inline CSS import time
import pandas as pd
from dash import Dash, dcc, html, Input, Output, State
import plotly.express as px
import dash_bootstrap_components as dbc
df = px.data.stocks()
df['date'] = pd.to_datetime(df['date'])
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout = dbc.Container([
dbc.Label('Plot Type', className="fw-bold"),
dcc.Dropdown(
id='datepicker-plots-x-dropdown',
options=[
{'label': 'Line Plot', 'value': 'line'},
{'label': 'Scatter Plot', 'value': 'scatter'},
{'label': 'Area Plot', 'value': 'area'},
{'label': 'Correlation Matrix', 'value': 'correlation'}
],
clearable=False,
value='correlation',
className='mb-3'
),
dbc.Row([
dbc.Col([
dbc.Label('Start Date', className="me-3 fw-bold"),
dcc.DatePickerSingle(
id='datepicker-plots-x-start-date',
date=df['date'].min(),
min_date_allowed=df['date'].min(),
max_date_allowed=df['date'].max(),
placeholder='Select a date'
),
], width="auto"
),
dbc.Col([
dbc.Label('End Date', className="me-3 fw-bold"),
dcc.DatePickerSingle(
id='datepicker-plots-x-end-date',
date=df['date'].max(),
min_date_allowed=df['date'].min(),
max_date_allowed=df['date'].max(),
placeholder='Select a date'
),
], width="auto"
),
], justify="evenly"),
dbc.Button('Submit', id='datepicker-plots-x-submit', n_clicks=0, className="mx-auto my-4 d-block"),
html.Div(id='datepicker-plots-x-error-msg', className='text-center fs-3 text-warning m-4'),
dcc.Loading(
id="datepicker-plots-x-loading",
type="circle",
children=[html.Div(id='datepicker-plots-x-graph', children=[], style={'height':400})],
),
], fluid=True)
# no changes to the callback If you want to keep the current plan and not use Bootstrap, then please remove the Bootstrap stylesheet, then also try to minimize the amount inline CSS in the
Here is the first part of the app without using Bootstrap. It has unnecessary inline CSS removed: import pandas as pd
from dash import Dash, dcc, html, Input, Output, State
import plotly.express as px
import time
df = px.data.stocks()
df['date'] = pd.to_datetime(df['date'])
app = Dash(__name__)
app.layout = html.Div([
html.Label('Plot Type', style={'fontWeight': 'bold'}),
dcc.Dropdown(
id='datepicker-plots-x-dropdown',
options=[
{'label': 'Line Plot', 'value': 'line'},
{'label': 'Scatter Plot', 'value': 'scatter'},
{'label': 'Area Plot', 'value': 'area'},
{'label': 'Correlation Matrix', 'value': 'correlation'}
],
clearable=False,
value='correlation',
),
html.Div([
html.Div([
html.Label('Start Date', style={'marginRight': '10px', 'fontWeight': 'bold'}),
dcc.DatePickerSingle(
id='datepicker-plots-x-start-date',
date=df['date'].min(),
min_date_allowed=df['date'].min(),
max_date_allowed=df['date'].max(),
placeholder='Select a date'
),
]),
html.Div([
html.Label('End Date', style={'marginRight': '10px', 'fontWeight': 'bold'}),
dcc.DatePickerSingle(
id='datepicker-plots-x-end-date',
date=df['date'].max(),
min_date_allowed=df['date'].min(),
max_date_allowed=df['date'].max(),
placeholder='Select a date'
),
],),
], style={'display': 'flex', 'justifyContent': 'space-evenly', 'marginTop':20}),
html.Div([
html.Button('Submit', id='datepicker-plots-x-submit', n_clicks=0, style={'backgroundColor': '#1976D2', 'color': 'white', 'border': 'none', 'padding': '10px 20px', 'borderRadius': '4px'})
], style={'display': 'flex', 'justifyContent': 'center', 'marginTop': '20px'}),
html.Div(id='datepicker-plots-x-error-msg', style={'color': 'orange', 'marginTop': '20px', 'fontSize': 30, 'textAlign': 'center'}),
dcc.Loading(
id="datepicker-plots-x-loading",
type="circle",
children=[html.Div(id='datepicker-plots-x-graph', children=[], style={'marginTop': '20px', 'height':400})],
),
])
# No change to the callbacks |
Hi,
Thank you for your email.
I am so sorry I lost it somewhere and just checked. I can start work on
this again. Will do the needed changes and update!
Best,
Nidhi
…On Fri, Jul 12, 2024 at 6:45 PM Ann Marie Ward ***@***.***> wrote:
Hi @nidhikamath2102 <https://github.com/nidhikamath2102>
Thanks for doing the update 🙂
I see you removed the dash-bootstrap-components as I suggested, but you
have added back a Bootstrap stylesheet. We need to decide if we are using
Bootstrap or not. Either way is OK, just let me know how you would like to
proceed, then we can fine tune from there.
If you would like to continue to use Bootstrap, then I recommend that you
keep the dbc library and leverage the tools available so you can
eliminate most of the inline CSS. You can do that by using the dbc.Row
and dbc.Col components and the Bootstrap utiltity classes.
For exampe:
className="mb-2 fw-bold"
instead of
style={"marginBottom": "20px", "fontWeight": "bold"}
You might find this site helpful - it has more info on the utility classes
https://dashcheatsheet.pythonanywhere.com/
In this example note that there is only one inline CSS
style={'height':400} . This will center the dcc.Loading when the app
starts or if there is an error message:
import timeimport pandas as pdfrom dash import Dash, dcc, html, Input, Output, Stateimport plotly.express as pximport dash_bootstrap_components as dbc
df = px.data.stocks()df['date'] = pd.to_datetime(df['date'])app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
app.layout = dbc.Container([
dbc.Label('Plot Type', className="fw-bold"),
dcc.Dropdown(
id='datepicker-plots-x-dropdown',
options=[
{'label': 'Line Plot', 'value': 'line'},
{'label': 'Scatter Plot', 'value': 'scatter'},
{'label': 'Area Plot', 'value': 'area'},
{'label': 'Correlation Matrix', 'value': 'correlation'}
],
clearable=False,
value='correlation',
className='mb-3'
),
dbc.Row([
dbc.Col([
dbc.Label('Start Date', className="me-3 fw-bold"),
dcc.DatePickerSingle(
id='datepicker-plots-x-start-date',
date=df['date'].min(),
min_date_allowed=df['date'].min(),
max_date_allowed=df['date'].max(),
placeholder='Select a date'
),
], width="auto"
),
dbc.Col([
dbc.Label('End Date', className="me-3 fw-bold"),
dcc.DatePickerSingle(
id='datepicker-plots-x-end-date',
date=df['date'].max(),
min_date_allowed=df['date'].min(),
max_date_allowed=df['date'].max(),
placeholder='Select a date'
),
], width="auto"
),
], justify="evenly"),
dbc.Button('Submit', id='datepicker-plots-x-submit', n_clicks=0, className="mx-auto my-4 d-block"),
html.Div(id='datepicker-plots-x-error-msg', className='text-center fs-3 text-warning m-4'),
dcc.Loading(
id="datepicker-plots-x-loading",
type="circle",
children=[html.Div(id='datepicker-plots-x-graph', children=[], style={'height':400})],
),
], fluid=True)
# no changes to the callback
If you want to keep the current plan and not use Bootstrap, then please
remove the Bootstrap stylesheet, then also try to minimize the amount
inline CSS in the style component. Some things have no effect, like for
the button this can be removed:
'textAlign': 'center', 'textDecoration': 'none', 'display': 'inline-block', 'fontSize': '16px', 'margin': '4px 2px', 'cursor': 'pointer',
Here is the first part of the app without using Bootstrap. It has
unnecessary inline CSS removed:
import pandas as pdfrom dash import Dash, dcc, html, Input, Output, Stateimport plotly.express as pximport time
df = px.data.stocks()df['date'] = pd.to_datetime(df['date'])app = Dash(__name__)
app.layout = html.Div([
html.Label('Plot Type', style={'fontWeight': 'bold'}),
dcc.Dropdown(
id='datepicker-plots-x-dropdown',
options=[
{'label': 'Line Plot', 'value': 'line'},
{'label': 'Scatter Plot', 'value': 'scatter'},
{'label': 'Area Plot', 'value': 'area'},
{'label': 'Correlation Matrix', 'value': 'correlation'}
],
clearable=False,
value='correlation',
),
html.Div([
html.Div([
html.Label('Start Date', style={'marginRight': '10px', 'fontWeight': 'bold'}),
dcc.DatePickerSingle(
id='datepicker-plots-x-start-date',
date=df['date'].min(),
min_date_allowed=df['date'].min(),
max_date_allowed=df['date'].max(),
placeholder='Select a date'
),
]),
html.Div([
html.Label('End Date', style={'marginRight': '10px', 'fontWeight': 'bold'}),
dcc.DatePickerSingle(
id='datepicker-plots-x-end-date',
date=df['date'].max(),
min_date_allowed=df['date'].min(),
max_date_allowed=df['date'].max(),
placeholder='Select a date'
),
],),
], style={'display': 'flex', 'justifyContent': 'space-evenly', 'marginTop':20}),
html.Div([
html.Button('Submit', id='datepicker-plots-x-submit', n_clicks=0, style={'backgroundColor': '#1976D2', 'color': 'white', 'border': 'none', 'padding': '10px 20px', 'borderRadius': '4px'})
], style={'display': 'flex', 'justifyContent': 'center', 'marginTop': '20px'}),
html.Div(id='datepicker-plots-x-error-msg', style={'color': 'orange', 'marginTop': '20px', 'fontSize': 30, 'textAlign': 'center'}),
dcc.Loading(
id="datepicker-plots-x-loading",
type="circle",
children=[html.Div(id='datepicker-plots-x-graph', children=[], style={'marginTop': '20px', 'height':400})],
),
])
# No change to the callbacks
—
Reply to this email directly, view it on GitHub
<#160 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMQIM4DKBASTCF53P3FSW4LZMBMAZAVCNFSM6AAAAABKSBEM4WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRWGQ2TKNBVGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hi, I have created a pull request for the datepicker_plots. Kindly check this and let me know if any changes are needed.