def set_table_columns(columns): if columns is None: raise PreventUpdate return [{ 'id': c, 'name': c.replace('_', ' ').title(), 'type': 'numeric' if 'ount' in c else 'text', 'format': Format(group=',') if 'ount' in c else None } for c in columns]
def populate_table_data(serp_results): if serp_results is None: raise PreventUpdate df = pd.DataFrame(serp_results, columns=serp_results[0].keys()) del df['pagemap'] columns = [{'name': re.sub('[A-Z]', r' \g<0>', x).title(), 'id': x, 'format': Format(group=',') if 'esults' in x else None} for x in df.columns] last_col = df.columns.tolist().index('totalResults') + 1 return df.iloc[:, :last_col].to_dict('rows'), columns[:last_col]
dcc.Loading([ DataTable( id='table', style_cell={ 'font-family': 'Source Sans Pro', 'minWidth': 100 }, columns=[{ 'name': i, 'id': i, 'type': 'numeric' if i == 'Tweet Volume' else None, 'format': Format(group=',') if i == 'Tweet Volume' else None } for i in TABLE_COLS], sort_action='native', fixed_rows={ 'headers': True, 'data': 0 }, data=pd.DataFrame( {k: ['' for i in range(10)] for k in TABLE_COLS}).to_dict('rows'), ), ]), ], style={ 'width': '95%', 'margin-left': '2.5%',
'textAlign': 'right' }, { 'if': { 'column_id': 'Topic' }, 'textAlign': 'center' }], columns=[{ 'name': i, 'id': i, 'type': 'numeric' if i == 'Tweet Volume' else None, 'format': Format(group=',') if i == 'Tweet Volume' else None } for i in TABLE_COLS], sort_action='native', export_headers='names', export_format='csv', page_action='none', style_table={'overflowX': 'scroll'}, fixed_rows={ 'headers': True, 'data': 0 }, data=pd.DataFrame({ k: ['' for i in range(10)] for k in TABLE_COLS }).to_dict('rows'))
style_header={'textAlign': 'center'}, style_cell={'font-family': 'Source Sans Pro', 'minWidth': 100, 'textAlign': 'left' }, style_cell_conditional=[ {'if': {'column_id': 'Tweet Volume'}, 'textAlign': 'right'}, {'if': {'column_id': 'Local Rank'}, 'textAlign': 'right'}, {'if': {'column_id': 'Topic'}, 'textAlign': 'center'} ], columns=[{'name': i, 'id': i, 'type': 'numeric' if i == 'Tweet Volume' else None, 'format': Format(group=',') if i == 'Tweet Volume' else None} for i in TABLE_COLS], sort_action='native', export_headers='names', export_format='csv', page_action='none', style_table={'overflowX': 'scroll'}, fixed_rows={'headers': True, 'data': 0}, data=pd.DataFrame({ k: ['' for i in range(10)] for k in TABLE_COLS }).to_dict('rows')) ], lg=10), ], style={'font-family': 'Source Sans Pro','width':'122%','margin-left':'-165px'}), ] ,style={'backgroundColor': "#000000", 'margin-top':'-30px', 'height':'2000px'}, )