Skip to content

Instantly share code, notes, and snippets.

View davidcomfort's full-sized avatar

David Michael Comfort davidcomfort

View GitHub Profile
# Callback for the Graphs
@app.callback(
Output('paid-search', 'figure'),
[Input('datatable-paid-search', "selected_rows"),
Input('my-date-picker-range-paid-search', 'end_date')])
def update_paid_search(selected_rows, end_date):
travel_product = []
travel_product_list = df[(df['Category'] == 'Paid Search')]['Placement type'].unique().tolist()
for i in selected_rows:
travel_product.append(travel_product_list[i])
######################## START Paid Search Layout ########################
layout_paid_search = html.Div([
html.Div([
# CC Header
Header(),
# Date Picker
html.Div([
dcc.DatePickerRange(
id='my-date-picker-range-paid-search',
min_date_allowed=dt(2018, 1, 1),
import dash_core_components as dcc
import dash_html_components as html
import dash_table
from components import Header, print_button
from datetime import datetime as dt
from datetime import date, timedelta
import pandas as pd
# Read in Travel Report Data
# Update page
# # # # # # # # #
@app.callback(Output('page-content', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
if pathname == '/cc-travel-report' or pathname == '/cc-travel-report/overview-birst/':
return layout_birst_category
elif pathname == '/cc-travel-report/overview-ga/':
return layout_ga_category
elif pathname == '/cc-travel-report/paid-search/':
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div([
style_cell_conditional=[{'if': {'column_id': 'Revenue YoY (%)',
'filter': 'Revenue_YoY_percent_conditional < num(0)'},
'color': 'red'}]
dt_columns = ['Placement type', 'Spend TY', 'Spend - LP', 'Spend PoP (Abs)', 'Spend PoP (%)', 'Spend LY', 'Spend YoY (%)', \
'Sessions - TY', 'Sessions - LP', 'Sessions - LY', 'Sessions PoP (%)', 'Sessions YoY (%)', \
'Bookings - TY', 'Bookings - LP', 'Bookings PoP (%)', 'Bookings PoP (Abs)', 'Bookings - LY', 'Bookings YoY (%)', 'Bookings YoY (Abs)', \
'Revenue - TY', 'Revenue - LP', 'Revenue PoP (Abs)', 'Revenue PoP (%)', 'Revenue - LY', 'Revenue YoY (%)', 'Revenue YoY (Abs)',]
conditional_columns = ['Spend_PoP_abs_conditional', 'Spend_PoP_percent_conditional', 'Spend_YoY_percent_conditional',
'Sessions_PoP_percent_conditional', 'Sessions_YoY_percent_conditional',
'Bookings_PoP_abs_conditional', 'Bookings_YoY_abs_conditional', 'Bookings_PoP_percent_conditional', 'Bookings_YoY_percent_conditional',
'Revenue_PoP_abs_conditional', 'Revenue_YoY_abs_conditional', 'Revenue_PoP_percent_conditional', 'Revenue_YoY_percent_conditional',]
html.Div([
dash_table.DataTable(
id='datatable-paid-search',
columns=[{"name": i, "id": i, 'deletable': True} for i in dt_columns]
+ [{"name": j, "id": j, 'hidden': 'True'} for j in conditional_columns],
editable=True,
n_fixed_columns=2,
style_table={'maxWidth': '1500px'},
row_selectable="multi",
selected_rows=[0],
dash_table.DataTable(
data=df.to_dict('rows'),
columns=[
{'name': i, 'id': i} for i in df.columns
],
style_data_conditional=[
{
'if': {
'column_id': 'Region',
'filter': 'Region eq "Montreal"'
pip install dash==0.39.0 # The core dash backend
pip install dash-html-components==0.14.0 # HTML components
pip install dash-core-components==0.44.0 # Supercharged components
pip install dash-table==3.6.0 # Interactive DataTable component (new!)
pip install dash-daq==0.1.0 # DAQ components (newly open-sourced!)