def load_agg_data(records: tp.List[dict]) -> dpv.PivotTable: n = sum(len(col) for col in records[0]) return dpv.PivotTable( id=str(pd.Timestamp.now()), data=records, unusedOrientationCutoff=n + 1, )
def pivot_table(app_option): df = get_df(app_option) p = pd.pivot_table( df, index=[ "load_balance", "cost_mix", "job_type", "cluster_name", ], values=[ "latency", "gb_price", ], aggfunc={ "latency": np.mean, "gb_price": np.mean, }, ) p = p.reset_index() vals = list(p.values.tolist()) cols = list(p.columns) flat_p = vals flat_p.insert(0, cols) pivot = dash_pivottable.PivotTable(data=flat_p, cols=["load_balance"], rows=["cost_mix"], vals=["gb_price"]) return [html.Div([pivot])]
def show_edd(contents, filename): if contents is not None: df = upload_2_df(contents, filename) data = df.to_dict('records') pivot = dash_pivottable.PivotTable(id='table', data=data, menuLimit=5000) return pivot
def Excelsheet_ui(df): Excelsheet = [ html.H5("Create Excelsheet for data"), dpivot.PivotTable(id='table', data=df.to_dict('records'), cols=[i for i in df.columns], colOrder="key_a_to_z", rows=[], rowOrder="key_a_to_z", rendererName="Grouped Column Chart", aggregatorName="Average", vals=[], valueFilter={}), ] return Excelsheet
def update_data(start_date, end_date): start_date = datetime.date(int(start_date.split('-')[0]), int(start_date.split('-')[1]), int(start_date.split('-')[2])) end_date = datetime.date(int(end_date.split('-')[0]), int(end_date.split('-')[1]), int(end_date.split('-')[2])) df2 = df[(df.DREG >= start_date) & (df.DREG <= end_date)] data2 = [df2.columns.tolist()] + df2.values.tolist() idd = str(random.randint(10000, 99999)) layout = [ dash_pivottable.PivotTable( id=idd, data=data2, cols=['SEGMENT'], rows=['TYPEOFCLIENTS'], vals=['CNT'] )] return layout
def show_pivottable(self, team=0): tm = self.projects[team] cycle_names = [s for s in tm.workflow] # Create a new data frame to normalize data cycle_data = tm.cycle_data.copy() # Convert to date only (insted of date time) cycle_data[cycle_names] = ( cycle_data[cycle_names].astype("<M8[D]").astype("<M8[ns]")) # Need to convert to list since this is what the data = cycle_data.values.tolist() data.insert(0, cycle_data.columns.to_list()) layout = html.Div(children=[ html.H1(children="Pivot Table"), html.Div(dash_pivottable.PivotTable(data=data)), ]) return layout
def time_series_pivot_table_preset_btn_clicked(*inputs_ignored): """Make a new pivot table according to the most recently clicked button. We can't have a callback function for each button because https://dash.plotly.com/callback-gotchas "A component/property pair can only be the Output of one callback".""" # From https://dash.plotly.com/advanced-callbacks "Determining which Input has fired" ctx = dash.callback_context if not ctx.triggered: # Use the first as the default when page is loaded. preset = more_itertools.first(TimeSeriesPivotTablePreset) else: preset = TimeSeriesPivotTablePreset.get_by_btn_id( ctx.triggered[0]["prop_id"].split(".")[0]) # Each PivotTable needs a unique id as a work around for # https://github.com/plotly/dash-pivottable/issues/10 return dash_pivottable.PivotTable( id=preset.tbl_id, data=per_timeseries_stats.pivottable_data, **preset.pivot_table_parameters, )
def generate_table(dframe: pd.DataFrame, **options: str) -> dash_pivottable.PivotTable: return dash_pivottable.PivotTable(data=[dframe.columns.to_list()] + dframe.values.tolist(), **options)
from django_plotly_dash import DjangoDash from .middleware import get_current_dataset import pandas as pd dset = get_current_dataset() sd = pd.read_excel(dset, sheet_name=None, header=None) hd = sd['Index'][[1, 4]].loc[3:].values.tolist() dini = {k[0].strip(): k[1].split('%') for k in hd} sd.pop('Index', None) pv = [] for k in sd: pv.append( dbc.Alert('Dataset: %s' % k, style={ "height": "35px", "padding-top": "2px", "margin-top": "3px", "margin-bottom": "1px", "font-weight": "bold" })) pv.append( dash_pivottable.PivotTable(data=sd[k].values.tolist(), rendererName=dini[k][0], cols=dini[k][1].split('&'), rows=dini[k][2].split('&'), aggregatorName=dini[k][3], vals=dini[k][4].split('&'), unusedOrientationCutoff='Infinity')) #pv.append(html.Hr()) app = DjangoDash('NomaDash') # replaces dash.Dash app.layout = html.Div(pv)
) app = dash.Dash(__name__) app.title = "Dash Pivottable" server = app.server app.layout = html.Div( [ Header("Dash Pivottable", app), dash_pivottable.PivotTable( id="table", data=data, cols=["Day of Week"], colOrder="key_a_to_z", rows=["Party Size"], rowOrder="key_a_to_z", rendererName="Grouped Column Chart", aggregatorName="Average", vals=["Total Bill"], valueFilter={"Day of Week": {"Thursday": False}}, ), html.Div(id="output"), ] ) @app.callback( Output("output", "children"), [ Input("table", "cols"), Input("table", "rows"),
cursor = graph.run("MATCH (a:EfigaRecord) RETURN a") rs = [] for record in cursor: rs.append(dict(record.values(0)[0])) df = pd.DataFrame(rs) #pivot_ui(df,outfile_path="pivottablejs.html") app.title = 'Efiga Data' app.layout = html.Div([ dash_pivottable.PivotTable(id='table', data=df.to_dict('records'), cols=[], colOrder="key_a_to_z", rows=[], rowOrder="key_a_to_z", rendererName="Table", aggregatorName="Count", vals=[], valueFilter={}), dcc.Markdown(id='output'), dcc.Markdown(id='output') ]) @app.callback(Output('output', 'children'), [ Input('table', 'cols'), Input('table', 'rows'), Input('table', 'rowOrder'), Input('table', 'colOrder'), Input('table', 'aggregatorName'),
import dash_html_components as html app = dash.Dash(__name__) app.scripts.config.serve_locally = True app.css.config.serve_locally = True app.title = 'My Dash example' app.layout = html.Div([ dash_pivottable.PivotTable( id='table', data=data, cols=['Day of Week'], colOrder="key_a_to_z", rows=['Party Size'], rowOrder="key_a_to_z", rendererName="Grouped Column Chart", aggregatorName="Average", vals=["Total Bill"], valueFilter={'Day of Week': { 'Thursday': False }}), dcc.Markdown(id='output') ]) @app.callback(Output('output', 'children'), [ Input('table', 'cols'), Input('table', 'rows'), Input('table', 'rowOrder'), Input('table', 'colOrder'),
dash_pivottable.PivotTable( id='table', data=data, cols=['Day of Week'], colOrder="key_a_to_z", rows=['Party Size'], rowOrder="key_a_to_z", rendererName="Grouped Column Chart", aggregatorName="Average", vals=["Total Bill"], valueFilter={'Day of Week': {'Thursday': False}}, attrClassified=True, attrCategory=[ { "name": "Payer", "subcategory": [ { "name": "Test1", "attributes": ['Payer Smoker'], "subcategory": [ { "name": "Test2", "attributes": ['Payer Gender'] } ] } ] }, { "name": "Money", "attributes": ['Tip', 'Total Bill'] }, { "name": "Others", "subcategory": [ { "name": "Test1", "attributes": ['Meal'], "subcategory": [ { "name": "Test2", "attributes": ['Day of Week'] }, { "name": "Test3", "attributes": ['Party Size'] } ] }, ] } ], attrLabel={ 'Tip': 'test label of tip' }, unclassifiedAttrName="Others", attrOrder=["Meal", "Day of Week", "Party Size", "Total Bill", "Tip", "Payer Smoker", "Payer Gender"], ),
import dash_pivottable import dash import dash_core_components as dcc from data import data from dash.dependencies import Input, Output import dash_html_components as html app = dash.Dash(__name__) app.scripts.config.serve_locally = True app.css.config.serve_locally = True app.layout = html.Div([ dash_pivottable.PivotTable(id='table', data=data), dcc.Markdown(id='output') ]) @app.callback(Output('output', 'children'), [ Input('table', 'cols'), Input('table', 'rows'), Input('table', 'rowOrder'), Input('table', 'colOrder'), Input('table', 'aggregatorName'), Input('table', 'rendererName') ]) def display_props(cols, rows, row_order, col_order, aggregator, renderer): return """ Columns: {} rows: {}
locations_src_file="./data/WPP2019_F01_LOCATIONS.XLSX", debug=debug, ) app = dash.Dash(__name__) app.layout = html.Div(children=[ html.H1(children="世界人口予測", style={"textAlign": "center"}), dash_pivottable.PivotTable( data=pop_data, cols=["Time"], rows=["GeoRegName"], vals=["Population"], hiddenFromDragDrop=["Population"], hiddenFromAggregators=[ "Time", "GeoRegName", "SubRegName", "Location", "PopType", ], aggregatorName="Sum", ), ]) if __name__ == "__main__": if not debug: app.run_server(host="0.0.0.0", port=8050) else: app.run_server(host="0.0.0.0", port=8050, debug=True)