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
# First Data Table Update Function | |
def update_first_datatable(start_date, end_date, category, aggregation): | |
if start_date is not None: | |
start_date = dt.strptime(start_date, '%Y-%m-%d') | |
start_date_string = start_date.strftime('%Y-%m-%d') | |
if end_date is not None: | |
end_date = dt.strptime(end_date, '%Y-%m-%d') | |
end_date_string = end_date.strftime('%Y-%m-%d') | |
days_selected = (end_date - start_date).days |
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
# Define Formatters | |
def formatter_currency(x): | |
return "${:,.0f}".format(x) if x >= 0 else "(${:,.0f})".format(abs(x)) | |
def formatter_currency_with_cents(x): | |
return "${:,.2f}".format(x) if x >= 0 else "(${:,.2f})".format(abs(x)) | |
def formatter_percent(x): | |
return "{:,.1f}%".format(x) if x >= 0 else "({:,.1f}%)".format(abs(x)) |
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
# Callback and update first data table | |
@app.callback(Output('datatable-paid-search', 'data'), | |
[Input('my-date-picker-range-paid-search', 'start_date'), | |
Input('my-date-picker-range-paid-search', 'end_date')]) | |
def update_data_1(start_date, end_date): | |
data_1 = update_first_datatable(start_date, end_date, 'Paid Search', 'Placement type') | |
return data_1 |
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
# First Data Table | |
html.Div([ | |
dash_table.DataTable( | |
id='datatable-paid-search', | |
columns=[{"name": i, "id": i, 'deletable': True} for i in dt_columns], | |
editable=True, | |
n_fixed_columns=2, | |
style_table={'maxWidth': '1500px'}, | |
row_selectable="multi", | |
selected_rows=[0], |
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
#datatable-paid-search > div > div > div.row.row-1 > div.cell.cell-1-0.dash-fixed-column { | |
flex: 0 0 auto; | |
left: 0; | |
position: sticky; | |
z-index: 0; | |
} |
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
#### Date Picker Callback | |
@app.callback(Output('output-container-date-picker-range-paid-search', 'children'), | |
[Input('my-date-picker-range-paid-search', 'start_date'), | |
Input('my-date-picker-range-paid-search', 'end_date')]) | |
def update_output(start_date, end_date): | |
string_prefix = 'You have selected ' | |
if start_date is not None: | |
start_date = dt.strptime(start_date, '%Y-%m-%d') | |
start_date_string = start_date.strftime('%B %d, %Y') | |
string_prefix = string_prefix + 'a Start Date of ' + start_date_string + ' | ' |
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
# Date Picker | |
html.Div([ | |
dcc.DatePickerRange( | |
id='my-date-picker-range-paid-search', | |
min_date_allowed=dt(2018, 1, 1), | |
max_date_allowed=df['Date'].max().to_pydatetime(), | |
initial_visible_month=dt(current_year,df['Date'].max().to_pydatetime().month, 1), | |
start_date=(df['Date'].max() - timedelta(6)).to_pydatetime(), | |
end_date=df['Date'].max().to_pydatetime(), | |
), |