def generate_table(dataframe, max_rows=15): return dt.DataTable( rows=dataframe.to_dict('records'), row_selectable=True, selected_row_indices=[], columns=(dataframe.columns), filterable=True, sortable=True, # sortColumn = True, max_rows_in_viewport=max_rows, )
def gen_plot(exp, picker, model_idx, counter): figure = exp.visualize(key=picker) if isinstance(figure, NDFrame): records = figure.to_dict("records") output_graph = dt.DataTable( rows=records, columns=figure.columns, filterable=True, sortable=True, editable=False, max_rows_in_viewport=10, id="graph-{0}-{1}".format(model_idx, counter), ) elif isinstance(figure, str): output_graph = html.Div([ html.Iframe( id="graph-{0}-{1}".format(model_idx, counter), sandbox="", srcDoc=figure, style={ "border": "0", "width": "100%", "height": "390px" }, ) ]) elif isinstance(figure, go.Figure): output_graph = dcc.Graph( id="graph-{0}-{1}".format(model_idx, counter), figure=figure, config={"displayModeBar": "hover"}, ) elif isinstance(figure, dash_base.Component): output_graph = figure output_graph.id = "graph-{0}-{1}".format(model_idx, counter) else: # pragma: no cover _type = type(figure) log.warning("Visualization type not supported: {0}".format(_type)) raise Exception("Not supported visualization type: {0}".format(_type)) idx_str = str(picker) name = exp.name output_div = html.Div( [ html.Div( html.Div("{0} [{1}]".format(name, idx_str), className="card-title"), className="card-header", ), html.Div(output_graph, className="card-body card-figure"), ], className="card", ) return output_div
def generate_table(dataframe): return dt.DataTable( id='filter-table-e', rows=dataframe.to_dict('records'), # optional - sets the order of columns columns=dataframe.columns, row_selectable=True, filterable=True, sortable=True, selected_row_indices=[], )
def contract_one_household(): return (dt.DataTable(rows=[{}], columns=[ "Contract ID", "Contract start time", "Contract agreement time", "Energy used (Wh)", "Consumer ID", "Producer ID" ], row_selectable=True, filterable=True, sortable=True, selected_row_indices=[], id="contract-table-one"))
def generate_table(dataframe, max_rows=10): return html.Div([ dt.DataTable( rows=dataframe.to_dict('records'), columns=(dataframe.columns), filterable=True, sortable=True, sortColumn=True, max_rows_in_viewport=max_rows, # row_selectable = True, ) ])
def _parse_csv(self, contents: str): content_type, content_string = contents.split(',') decoded = base64.b64decode(content_string) try: self.df = pd.read_csv(io.StringIO(decoded.decode('utf-8'))) except Exception as e: print(e) return html.Div(['There was an error processing the file']) return html.Div( [dt.DataTable(rows=self.df.head(20).to_dict('records'))])
def parse_contents(contents, filename, date): content_type, content_string = contents.split(",") decoded = base64.b64decode(content_string) try: if 'csv' in filename: data = pd.read_csv(io.StringIO(decoded.decode('utf-8')), skipinitialspace = True) print(data.columns[0]) elif 'xls' in filename: data = pd.read_excel(io.BytesIO(decoded)) except Exception as e: print(e) return html.Div(['There was an error processing this file. File type not supported?']) hospital_connections = go.Scatter(x=data.iloc[:,1], y=data.iloc[:,0], name='', opacity =1, mode = 'markers') diagnose_start_dates = [datetime.strptime(dat, '%Y-%m-%d').date() for dat in data.iloc[:,2].str.strip()] diagnose_end_dates = [datetime.strptime(dat, '%Y-%m-%d').date() for dat in data.iloc[:,3].str.strip()] covered_diagnose_timespans = [] for i in range (0,len(data.iloc[:,0])): hosp=[data.iloc[i,0],data.iloc[i,0]] dates=[diagnose_start_dates[i],diagnose_end_dates[i]] covered_diagnose_timespan = go.Scatter(x=dates, y=hosp, name='', opacity =1) covered_diagnose_timespans.append(covered_diagnose_timespan) return html.Div([ html.H1(filename), dt.DataTable( rows=data.to_dict('records'), row_selectable = True, filterable=True, sortable=True, selected_row_indices=[], max_rows_in_viewport = 50, id='datatable-hospitals' ), dcc.Graph( id='datagraph-hospitals', figure={ 'data': [hospital_connections], 'layout': go.Layout(title='Hospital connection dates', height=800) } ), dcc.Graph( id='chart-diagnose-coverage', figure={ 'data': covered_diagnose_timespans, 'layout' : go.Layout(title='Covered diagnose timespans per hospital', height=800) } ) ])
def update_figure(product_choice, qual_choice, test_choice, dut_choice, die_choice, manual_refresh, interval_refresh): def generate_table(): dbvalue = __BLK_GBB_DB__.format(product_choice) if not dut_choice: return [{}] if not die_choice: return [{}] testtype = str(".*," + test_choice + ",.*") duttype = str(".*," + dut_choice + ",.*") dietype = str(".*," + die_choice.split(',')[0].split('X')[1] + "," + die_choice.split(',')[1].split('Y')[1] + ",.*") query = { "$and": [ { "_id": { "$regex": testtype } }, { "_id": { "$regex": duttype } }, { "_id": { "$regex": dietype } }, ] } query_result = mongo_query.run_query(dbvalue, qual_choice, query) return tuple( dict(zip(row['_id_name'].split(','), row['_id'].split(','))) for row in query_result) return [ html.Div( html.B('Bad Block Table'), className='row panel-head theme-color-secondary', ), html.Div(dt.DataTable(id='R4GBB', rows=generate_table(), editable=False, row_selectable=True, filterable=True, sortable=True, selected_row_indices=[]), className="row panel-body"), ]
def render_datatable(data, colunas, id): datatable = dt.DataTable(id=id, rows=data, columns=colunas, enable_drag_and_drop=False, editable=False, filterable=True, sortable=True, max_rows_in_viewport=5, selected_row_indices=[], row_selectable=True) return datatable
def generateDashDataTable2(df): dte.DataTable(data=df.to_dict("rows"), columns=[{ "name": i, "id": i } for i in df.columns], style_data_conditional=[{ "if": { "row_index": 4 }, "backgroundColor": "#3D9970", 'color': 'white' }])
def create_table(lines, df, val): if lines and not isinstance(lines, list): df = pd.read_json(df, orient='split') if not val: x = len(df) val = [0, x] return html.Div([ # Use the DataTable prototype component:\ # github.com/plotly/dash-table-experiments dte.DataTable(rows=df[val[0]:val[1]].to_dict('records')), html.Hr() ])
def render_content(tab, entity=None): if tab == 'tab-1-example': rows, related = get_rows(entity, 1) if entity=='' or entity is None: return html.Div([ html.P('Please Select a Gene Name') ]) else: return html.Div([ html.H4('{} as Kinase'.format(entity)), html.Div([ dt.DataTable( rows = rows, columns=['KinaseLabel', 'SubstrateLabel', 'Score Range'], row_selectable=True, filterable=True, sortable=True, selected_row_indices=[], editable=False, id='tbl') ]), ]) elif tab == 'tab-2-example': rows, related = get_rows(entity, 2) return html.Div([ html.H4('{} as Substrate'.format(entity)), html.Div([ dt.DataTable( rows=rows, # df_subj.to_dict('records'), columns=['KinaseLabel', 'SubstrateLabel', 'Score Range'], row_selectable=True, filterable=True, sortable=True, selected_row_indices=[], editable=False, id='tbl') ]), ])
def get_similar_docs(sent): print('similar docs called ',sent) # path=glob.glob(r'*.csv') # df=pd.read_csv(path[0],encoding='ISO-8859-1') global similar_df similar_series=get_similar_records(sent,df[df.columns[0]]) similar_df=pd.DataFrame(columns=['Similar_sentences','labels']) similar_df['Similar_sentences']=similar_series print('check',similar_df.head()) # similar_df.to_csv return html.Div(dt.DataTable(rows=similar_df.to_dict('records'),id='edit-table-similar'),)
def update_table_output(jsonified_data): dff = pd.read_json(jsonified_data) return html.Div([ html.H3("View loaded data below:", style={'margin-left': '0'}), dt.DataTable(rows=dff.to_dict('records')), html.Hr(), html.Br(), html. H3("Please select columns in the left pane to produce a visualisation below" ) ])
def generate_table(main_database): dataframe_top_five_tweets = pd.DataFrame({ 'Tweet': dc.getTopFiveTweets(main_database)[0], 'Likes': dc.getTopFiveTweets(main_database)[1], 'Retweets' : dc.getTopFiveTweets(main_database)[2] }) return dt.DataTable( rows = dataframe_top_five_tweets.to_dict('records'), id = 'table_top_five', )
def parse_contents(contents, filename, date): content_type, content_string = contents.split(',') decoded = base64.b64decode(content_string) try: if 'csv' in filename: # Assume that the user uploaded a CSV file df = pd.read_csv( io.StringIO(decoded.decode('utf-8'))) elif 'xls' in filename: # Assume that the user uploaded an excel file df = pd.read_excel(io.BytesIO(decoded)) except Exception as e: print(e) return html.Div([ 'There was an error processing this file.' ]) return html.Div([ html.H3([ 'Selected dataset:' ], style = { 'margin-top' : '48px', 'margin-bottom': '8px', 'font-size': '24' } ), html.Br(), html.H3([ filename ], style = { 'margin-top' : '8px', 'margin-bottom': '20px', 'font-size': '24', 'font-weight': 'lighter' } ), # Use the DataTable prototype component: # github.com/plotly/dash-table-experiments dt.DataTable(rows=df.to_dict('records')), ])
def update_output(contents): if contents is not None: content_type, content_string = contents.split(',') if 'csv' in filepath: df = pd.read_csv(io.StringIO(base64.b64decode( content_string).decode('utf-8'))) return html.Div([ dt.DataTable( rows=df.to_dict('records'), columns=['city', 'country']), html.Hr(), html.Div('Raw Content'), html.Pre(contents, style=pre_style) ]) elif 'xls' in filepath: df = pd.read_excel(io.BytesIO(base64.b64decode( content_string))) return html.Div([ dt.DataTable( rows=df.to_dict('records'), columns=['city', 'country']), html.Hr(), html.Div('Raw Content'), html.Pre(contents, style=pre_style) ]) elif 'image' in content_type: return html.Div([ html.Img(src=contents), html.Hr(), html.Div('Raw Content'), html.Pre(contents, style=pre_style) ]) else: return html.Div([ html.Hr(), html.Div('Raw Content'), html.Pre(contents, style=pre_style) ])
def parse_contents(contents, filename, date): conn = sqlite3.connect(filename) c = conn.cursor() df = pd.read_sql( "SELECT * FROM `PHY12-ABCDEFG-201710131122` ORDER BY `_rowid_` ASC LIMIT 0, 50000", conn) df = df.to_json() print df return html.Div([ html.H5(filename), html.H6(datetime.datetime.fromtimestamp(date)), dt.DataTable(rows=df), html.Hr() ])
def ek_func(DF_STU): table = html.Div(children=[ html.H4('Your Data'), dt.DataTable(rows=DF_STU.to_dict('records'), columns=sorted(DF_STU.columns), row_selectable=True, filterable=True, sortable=True, selected_row_indices=[], id='datatable-simple'), html.Div(id='selected-indexes') ]) return table
def portfolio_record(portfolio: RandomPortfolio): frame = pd.DataFrame([portfolio.tickers, portfolio.weights]).T frame.columns = ['Ticker', "Weight"] frame['Weight'] = (frame['Weight']*100).map(lambda x: "{0:.2f}%".format(x)) return html.Div([ html.H1("Account n° {} - Portfolio composition".format(portfolio.id), className='panel-heading'), dtex.DataTable( rows=frame.to_dict('records'), filterable=True, sortable=True, id='records_table' ) ], className='panel panel-default')
def gen_overview_tab(): """ Generates overview tab. Returns: Dash component that handles overview tab entire. """ # Define components ctx = app.config['ctx'] records = get_model_records(ctx) table = dt.DataTable(rows=records, columns=['Name', 'Type'], row_selectable=False, filterable=False, sortable=True, selected_row_indices=[], editable=False, max_rows_in_viewport=10, id='overview-table-dt') markdown = """ Welcome to Interpret ML's dashboard. Here you will find en-masse visualizations for your machine learning pipeline. *** The explanations available are split into tabs, each covering an aspect of the pipeline. - **Data** covers exploratory data analysis, designed mostly for feature-level. - **Performance** covers model performance both overall and user-defined groups. - **Global** explains model decisions overall. - **Local** explains a model decision for every instance/observation. """ # Wrap as cards. cards = [] cards.append( html.Div([ html.Div(html.Div('Introduction', className='card-title'), className='card-header'), html.Div(dcc.Markdown(markdown), className='card-body'), ], className='card')) cards.append( html.Div([ html.Div(html.Div('Available Explanations', className='card-title'), className='card-header'), html.Div(html.Div(table), className='card-body'), ], className='card')) return html.Div(cards)
def show_sites_1(id, rows, selected_row_indices): if len(selected_row_indices) == 0: return html.P('Please select a row in main table on the left.') else: selected_rows = [rows[i] for i in selected_row_indices] # print(selected_rows) rows = get_site_rows(selected_rows) return dt.DataTable(rows=rows, columns=['KinaseLabel', 'SubstrateLabel', 'Site', 'Score'], row_selectable=False, filterable=False, sortable=True, selected_row_indices=[], editable=False)
def create_tab4(): table1 = pd.read_csv('inputTables/tab4/input1.csv') table2 = pd.read_csv('inputTables/tab4/input2.csv') return html.Div([ html.H4('Control and Risk Details'), dt.DataTable(rows=table1.to_dict('records'), columns=table1.columns, id='table_1'), html.H4('Population and Sample Procedures'), dt.DataTable(rows=table2.to_dict('records'), columns=table2.columns, id='table_2'), html.H4('Test of Design Steps Performed'), dcc.Textarea(placeholder='Enter Data...', value='', style={'width': '100%'}, id='table_3'), html.H4('Test of Design Narrative'), dcc.Textarea(placeholder='Enter Data...', value='', style={'width': '100%'}, id='table_4'), html.H4('Test of Design Evidence'), dcc.Textarea(placeholder='Enter Data...', value='', style={'width': '100%'}, id='table_5'), html.H4('Test of Design Results'), dcc.Textarea(placeholder='Enter Data...', value='', style={'width': '100%'}, id='table_6'), html.Button('Download', id='button4', style={'margin-top': '10px'}) ], id='tab_4', className="tab_class_4 container", style={'padding': '6px'})
def update_output(contents): if contents is not None: content_type, content_string = contents.split(',') if 'csv' in content_type: df = pd.read_csv( io.StringIO(base64.b64decode(content_string).decode('utf-8'))) return html.Div([ dt.DataTable(rows=df.to_dict('records')), html.Hr(), html.Div('Raw Content'), html.Pre(contents, style=pre_style) ]) elif 'image' in content_type: return html.Div([ html.Img(src=contents), html.Hr(), html.Div('Raw Content'), html.Pre(contents, style=pre_style) ]) else: # xlsx will have 'spreadsheet' in `content_type` but `xls` won't # have anything try: df = pd.read_excel(io.BytesIO( base64.b64decode(content_string))) return html.Div([ dt.DataTable(rows=df.to_dict('records')), html.Hr(), html.Div('Raw Content'), html.Pre(contents, style=pre_style) ]) except: return html.Div([ html.Hr(), html.Div('Raw Content'), html.Pre(contents, style=pre_style) ])
def generate_table(dataframe, max_rows=15): return dt.DataTable( rows=dataframe.to_dict('records'), # optional - sets the order of columns columns=dataframe.columns, row_selectable=True, filterable=True, sortable=True, selected_row_indices=[], id='datatable-gapminder' ) '''return html.Table(
def return_Layout(dfCountry, country): return html.Div([ html.H5(country + ' GPD Time Series Table', style={'textAlign': 'center'}), dt.DataTable( rows=dfCountry.to_dict('records'), # optional - sets the order of columns columns=sorted(dfCountry.columns), row_selectable=True, filterable=True, sortable=True, selected_row_indices=[], id='datatable-gdpCountry'), ])
def loading_pairs(n_clicks, rows, selected_row_indices): if n_clicks == 0: print('n_clicks == 0') return dt.DataTable( rows=pc.to_dict('records'), columns=['brand'], row_selectable=True, filterable=True, sortable=True, selected_row_indices=[], resizable=True, max_rows_in_viewport=5, #min_width=400, id='dt_words_pair') else: return None
def create_datatable(self, data_dict, selected_indices): return dt.DataTable( rows=data_dict, # Table data columns=list(data_dict[0].keys()), # Column names row_selectable=True, # Able to select independent rows filterable=True, # Able to filter columns by value # debounced=True, # Delay after filtering before callback sortable=True, # Able to sort by column values editable=False, # Not able to edit values resizable=True, # Able to resize columns to fit data max_rows_in_viewport=5, # Scroll if more than 5 rows selected_row_indices=selected_indices, # selected rows sortColumn='Task', # set sorting by task sortDirection='ASC', # set increasing order for sort id='table-clowdrexp') # Use the same ID for callbacks
def setTable(self, rows, headers): self.__setValues(rows) self.__df.define(self.__values, columns=headers) self.__dt = dt.DataTable( rows=self.__df.to_dict('records'), #optional - sets the order of columns #columns=sorted(self.__df.columns()), row_selectable=True, filterable=True, sortable=True, selected_row_indices=[] #, #id='datatable-gapminder' todo ) self.__rows = rows self.__headers = headers super().setDashRendering(self.__dt)
def create_consumer_modal_form(did, name, temp, dtype, load): return html.Div(className="consumer_modal_form", children=[ html.Div(className="dev_id", children=[ html.Div("Device ID:"), dcc.Input(id="new_device_id", type="number", value=did, className="modal_input_field") ]), html.Div(className="dev_name", children=[ html.Div("Device Name:"), dcc.Input(id="new_device_name", type="text", value=name, className="modal_input_field") ]), html.Div(className="dev_temp", children=[ html.Div("Device Template:"), dcc.Input(id="new_device_template", type="number", value=temp, className="modal_input_field") ]), html.Div(className="dev_type", children=[ html.Div("Device Type:"), dcc.Dropdown(id="new_device_type", options=[{ "label": "Consumer", "value": "consumer" }], value=dtype) ]), dcc.Upload(id="load_prediction_upload", className="dev_load", children=[html.Button("Add load csv file") ]), html.Div(className="load_table", children=[ dt.DataTable(id="load_prediction_table", rows=load) ]) ])