def getSummary(df_tws): # ANOVA in Python: https://www.pythonfordatascience.org/anova-python/ results_data = pd.DataFrame(df_tws.describe()) df_results = results_data.reset_index() source = ColumnDataSource(df_results) template = """ <div style="background:<%= (function colorfromint(){ if(value == 1){ return("blue")} else{return("red")} }()) %>; color: white"> <%= value %></div> """ formater = HTMLTemplateFormatter(template=template) columns = [ TableColumn(field='index', title='Statistic'), TableColumn(field='retweets', title='Retweets'), TableColumn(field='favorites', title='Favourites'), TableColumn(field='sentiment', title='Sentiment', formatter=formater) ] data_table = DataTable(source=source, columns=columns, width=350, height=280, editable=False, index_position=None) return data_table
def save_df_as_image(df, path): source = ColumnDataSource(df) df_columns = [df.index.name] df_columns.extend(df.columns.values) columns_for_table=[] template=""" <div style="color:<%= (function colorfromint(){ if (Variation > 0) {return('green')} else if (Variation < 0) {return('red')} else {return('blue')} }())%>;"> <%=value%> </div> """ formatter = HTMLTemplateFormatter(template=template) for column in df_columns: if(column == 'Variation'): columns_for_table.append(TableColumn(field=column, title=column, formatter=formatter)) else: columns_for_table.append(TableColumn(field=column, title=column)) full_height=(26*len(df.index)) data_table = DataTable(source=source, columns=columns_for_table,fit_columns=True,height=full_height,width_policy="auto",index_position=None) export_png(data_table, filename = path)
def _create_column(self, name: str) -> TableColumn: formatter = HTMLTemplateFormatter() if self._is_plot_column( name) else None return TableColumn(field=name, title=name, formatter=formatter, width=self.default_plot_width if self._is_plot_column(name) else None)
def setupTable(cds, template=None): """ """ if template is None: # Define our color format/template # This uses Underscore’s template method and syntax. # http://underscorejs.org/#template template = """ <b> <div style="background:<%= (function ageColorer(){ if(ageStatement){ return("#ff0000;opacity:0.25;") } else{ return("none;") } }()) %>;"> <%= value %> </div> </b> """ elif template == 'none': template = "" else: template = template formatter = HTMLTemplateFormatter(template=template) # Now we construct our table by specifying the columns we actually want. # We ignore the 'ageStatement' row for this because we # just get at it via the formatter/template defined above labelCol = TableColumn(field='labels', title='Parameter', sortable=False) valueCol = TableColumn(field='values', title='Value', sortable=False, formatter=formatter) cols = [labelCol, valueCol] nRows = len(cds.data['labels']) # Now actually construct the table dtab = DataTable(columns=cols, source=cds) # THIS IS SO GOD DAMN IRRITATING # It won't accept this in a theme file because it seems like there's a # type check on it and 'None' is not the 'correct' type dtab.index_position = None # This is also irritating # Specify a css group to be stuffed into the resulting div/template # which is then styled by something else. Can't get it thru the theme :( dtab.css_classes = ["nightwatch_bokeh_table"] return dtab, nRows
def create_case_details_tab(): "Factory for creating 5th tab." ## Data Sources source_df, source_CDS = get_line_list_data() ## Data Table link_template = """<a href="<%= value %>">Link</a>""" overflow_paragraph_template = f"""<p style="overflow: auto; white-space: pre-wrap; padding: 0; margin: 0; height: 100%; width: inherit;"><%= value %></p>""" data_table_columns = [ TableColumn(field="country", title="Country", width=150), TableColumn(field="location", title="Location", formatter=HTMLTemplateFormatter(template=overflow_paragraph_template), width=150), TableColumn(field="link", title="Link", formatter=HTMLTemplateFormatter(template=link_template), width=50), TableColumn(field="age", title="Age", width=50), TableColumn(field="gender", title="Gender", width=100), TableColumn(field="reporting_date", title="Reporting Date", width=200), TableColumn(field="summary", title="Summary", formatter=HTMLTemplateFormatter(template=overflow_paragraph_template), width=450), TableColumn(field="exposure_start", title="Exposure Start", width=200), TableColumn(field="exposure_end", title="Exposure End", width=200), TableColumn(field="symptoms", title="Symptoms", formatter=HTMLTemplateFormatter(template=overflow_paragraph_template), width=150), TableColumn(field="symptom_onset", title="Symptom Onset", width=250), TableColumn(field="from_wuhan", title="From Wuhan", width=150), TableColumn(field="visiting_wuhan", title="Visiting Wuhan", width=200), TableColumn(field="recovered", title="Recovered", width=150), TableColumn(field="recovered_date", title="Recovery Date", width=200), TableColumn(field="death", title="Death", width=100), TableColumn(field="death_date", title="Death Date", width=150), ] data_table = DataTable( columns=data_table_columns, source=source_CDS, row_height=100, sizing_mode='scale_both' ) child = row([data_table]) return Panel(child=child, title="Case Details")
def update(attr, old, new): new_source_table, new_source_color = get_data() new_template = '<div style="background:<%=(function colorfromint(){'+\ f'if({str(new_source_color.data["top_co"])}.indexOf(value) > -1)'+\ '{return("#ffb3b3")}else{return("white")}}()) %>; color: black"> <%= value %></div>' new_formatter = HTMLTemplateFormatter(template=new_template) new_columns = [] for colnames in new_source_table.data.keys(): if colnames != 'index': new_columns.append( TableColumn(field=colnames, title=colnames, formatter=new_formatter)) table.source = new_source_table table.columns = new_columns
pandata.fillna('None', inplace=True) # just replace missing values with zero source = ColumnDataSource(pandata) SIZES = list(range(6, 22, 3)) columns = [ TableColumn(field="HostnameIP", title="Address", width=450), TableColumn(field="Malware", title="Malware"), TableColumn(field="Compromise", title="Compromise"), TableColumn(field="Lookup:Success", title="Success"), TableColumn(field="Lookup:IOCScanned", title="IOCScanned"), TableColumn(field="Lookup:HashScanned", title="HashScanned"), TableColumn(field="Lookup:Subnet", title="Subnet"), TableColumn(field='HostId', title='Result', formatter=HTMLTemplateFormatter( template='<a href="http://%s:%d/host-result/<%%= value %%>" target="_blank">#<%%= value %%></a>' % (LISTEN_ADDRESS, LISTEN_PORT))) ] data_table = DataTable(source=source, columns=columns, fit_columns=True) columns = sorted(pandata.columns) filtered_columns = [c for c in columns if 'Hostname' not in c and 'HostId' not in c] discrete = [x for x in columns if pandata[x].dtype == object] continuous = [x for x in columns if x not in discrete] quantileable = [x for x in continuous if len(pandata[x].unique()) > 1] def create_figure(): # args = curdoc().session_context.request.arguments # with open('args.txt', 'w') as the_file: # the_file.write(str(curdoc().session_context.request.arguments['batchid'])) # the_file.write(str(args))
elements['name_lower'] = elements['name'].str.lower() source = ColumnDataSource(elements) html_font_template = '<font color="<%= CPK %>"><%= value %></font>' html_image_template = """ <a href="http://images-of-elements.com/<%= value %>.php" target="_blank"> <img src="http://images-of-elements.com/<%= value %>.jpg" style="width:40px;height:40px;border:0"> </a> """ columns = [ TableColumn(field='atomic number', title='Atomic Number', formatter=NumberFormatter(text_align="right")), TableColumn(field='symbol', title='Symbol', formatter=StringFormatter(text_align="center")), TableColumn(field='name', title='Name', formatter=HTMLTemplateFormatter(template=html_font_template)), TableColumn(field='name_lower', title='Image', formatter=HTMLTemplateFormatter(template=html_image_template)) ] data_table = DataTable(source=source, columns=columns, editable=False, row_height=45) save(data_table)
'Unlikely': HTMLTemplateFormatter(template=""" <div style="background-color:<%= (function colorfromint(){ var thresh_1 = 8; var thresh_2 = 15; if (typeof Unlikely == 'string'){ var val = Unlikely.split(' '); val = val.slice(-1)[0] console.log(val); if(val < thresh_1 ) {return("#1aff1a")} else if (val < thresh_2) {return("#CCCC00")} else {return("#ff6633")} } else{ if(Unlikely < thresh_1 ) {return("#1aff1a")} else if (Unlikely < thresh_2) {return("#CCCC00")} else if (Unlikely >= thresh_2) {return("#ff6633")} } }()) %>; color: #111111;font-size:2em;text-align:center"> <%= value %> </div> """), 'Seldom':
end=110000, value=(10000, 110000), step=1000, format="0,0") slider.on_change('value', lambda attr, old, new: update()) # HTML formatter code for error_message column. Makes the text in the column # wrap. # TODO if the text truncates, we should have an ellipsis to indicate this # has happened, but I can't figure out how to do this right now. text_wrap_template = \ """<span style="overflow-wrap: normal; white-space: normal;"> <%= value %></span>""" text_wrap_formatter = HTMLTemplateFormatter(template=text_wrap_template) columns = [ TableColumn(field="name", title="Employee Name", width=150), TableColumn(field="salary", title="Income", formatter=NumberFormatter(format="$0,0.00"), width=80), TableColumn(field="years_experience", title="Experience (years)", width=150), TableColumn(field="points", title="Points", formatter=NumberFormatter(format="0,0.00"), width=100), TableColumn(field="commute_distance",
def get_summarytable(exposures): ''' Generates a summary table of key values for each night observed. Uses collections.Counter(), OrderedDict() Args: exposures: Table of exposures with columns... Returns a bokeh DataTable object. ''' nights = np.unique(exposures['NIGHT']) isbright = (exposures['PROGRAM'] == 'BRIGHT') isgray = (exposures['PROGRAM'] == 'GRAY') isdark = (exposures['PROGRAM'] == 'DARK') iscalib = (exposures['PROGRAM'] == 'CALIB') num_nights = len(nights) brights = list() grays = list() darks = list() calibs = list() totals = list() for n in nights: thisnight = exposures['NIGHT'] == n totals.append(np.count_nonzero(thisnight)) brights.append(np.count_nonzero(thisnight & isbright)) grays.append(np.count_nonzero(thisnight & isgray)) darks.append(np.count_nonzero(thisnight & isdark)) calibs.append(np.count_nonzero(thisnight & iscalib)) med_air = get_median('AIRMASS', exposures) med_seeing = get_median('SEEING', exposures) med_exptime = get_median('EXPTIME', exposures) med_transp = get_median('TRANSP', exposures) med_sky = get_median('SKY', exposures) source = ColumnDataSource(data=dict( nights=list(nights), totals=totals, brights=brights, grays=grays, darks=darks, calibs=calibs, med_air=med_air, med_seeing=med_seeing, med_exptime=med_exptime, med_transp=med_transp, med_sky=med_sky, )) formatter = NumberFormatter(format='0,0.00') template_str = '<a href="night-<%= nights %>.html"' + ' target="_blank"><%= value%></a>' columns = [ TableColumn(field='nights', title='NIGHT', width=100, formatter=HTMLTemplateFormatter(template=template_str)), TableColumn(field='totals', title='Total', width=50), TableColumn(field='brights', title='Bright', width=50), TableColumn(field='grays', title='Gray', width=50), TableColumn(field='darks', title='Dark', width=50), TableColumn(field='calibs', title='Calibs', width=50), TableColumn(field='med_exptime', title='Median Exp. Time', width=100), TableColumn(field='med_air', title='Median Airmass', width=100, formatter=formatter), TableColumn(field='med_seeing', title='Median Seeing', width=100, formatter=formatter), TableColumn(field='med_sky', title='Median Sky', width=100, formatter=formatter), TableColumn(field='med_transp', title='Median Transparency', width=115, formatter=formatter), ] summary_table = DataTable(source=source, columns=columns, width=900, sortable=True, fit_columns=False) return summary_table
def setup_pop_table(self, **kwargs): """ ???+ note "Set up a bokeh `DataTable` widget for monitoring subset data populations." | Param | Type | Description | | :--------- | :----- | :--------------------------- | | `**kwargs` | | forwarded to the `DataTable` | """ subsets = [ *self.__class__.SCRATCH_SUBSETS, *self.__class__.PUBLIC_SUBSETS, *self.__class__.PRIVATE_SUBSETS, ] pop_source = ColumnDataSource(dict()) pop_columns = [ TableColumn(field="label", title="label"), *[ TableColumn(field=f"count_{_subset}", title=_subset) for _subset in subsets ], TableColumn( field="color", title="color", formatter=HTMLTemplateFormatter(template=COLOR_GLYPH_TEMPLATE), ), ] self.pop_table = DataTable(source=pop_source, columns=pop_columns, **kwargs) def update_population(): """ Callback function. """ # make sure that the label coding is correct self.setup_label_coding() # re-compute label population eff_labels = [module_config.ABSTAIN_DECODED, *self.classes] color_dict = auto_label_color(self.classes) eff_colors = [color_dict[_label] for _label in eff_labels] pop_data = dict(color=eff_colors, label=eff_labels) for _subset in subsets: _subpop = self.dfs[_subset]["label"].value_counts() pop_data[f"count_{_subset}"] = [ _subpop.get(_label, 0) for _label in eff_labels ] # push results to bokeh data source pop_source.data = pop_data self._good( f"Population updater: latest population with {len(self.classes)} classes." ) update_population() self.dedup_trigger.on_click(update_population) # store the callback so that it can be referenced by other methods self._callback_update_population = update_population
def modify_document(self, doc): self.tb.lock() sink = bokehgui.vec_sink_f_proc(self.tb.get_num_channels(), "", 1) self.tb.connect((self.mag_to_zW, 0), (sink, 0)) self.tb.unlock() log_cds = ColumnDataSource(data=self.lw.get_table()) blw = BokehLogWatcher(doc, log_cds) logging.getLogger().addHandler(blw) def cleanup_session(session_context): self.tb.lock() self.tb.disconnect((self.mag_to_zW, 0), (sink, 0)) self.tb.unlock() logging.getLogger().removeHandler(blw) doc.on_session_destroyed(cleanup_session) doc.title = "Gal Scan GUI" plot_lst = [] plot = vec_sink_f(doc, plot_lst, sink, is_message=False) plot.initialize(update_time=100, legend_list=['']) plot.get_figure().aspect_ratio = 2 plot.set_y_axis([0, 10]) plot.set_y_label("Power at feed (zW / Hz)") plot.set_x_label("Frequency (MHz)") def set_x_values(): plot.set_x_values( np.linspace( self.tb.get_sdr_frequency() - (self.tb.get_output_vector_bandwidth() / 2), self.tb.get_sdr_frequency() + (self.tb.get_output_vector_bandwidth() / 2), self.tb.get_num_channels()) / 1e6) set_x_values() plot.enable_axis_labels(True) plot.set_layout(1, 0) plot.enable_max_hold() plot.format_line(0, "blue", 1, "solid", None, 1.0) azimuth = Knob(title="Azimuth", max=360, min=0, unit="°") elevation = Knob(title="Elevation", max=360, min=0, unit="°") rx_power = Knob(title="Average RX Power", digits=4, decimals=1, unit="dB(mW/Hz)") plot.stream.js_on_change( "streaming", CustomJS( args=dict(rx_power=rx_power), code=""" const data = cb_obj.data const average = data['y0'].reduce((a,b) => a+b)/data['y0'].length rx_power.value = (10*Math.log10(average))-180 """, )) log_table = SortedDataTable( source=log_cds, columns=[ TableColumn(field="asctime", title="Time", width=140), TableColumn(field="levelname", title="Level", width=60), TableColumn(field="message", title="Message", width=1500), ], autosize_mode="none", aspect_ratio=2, sizing_mode="stretch_width", sortable=True, ) gain = Slider(title="gain", value=self.tb.get_sdr_gain(), start=0, end=65) gain.on_change('value', lambda name, old, new: self.set_gain(new)) rx = ActiveButton(label="RX enabled") rx.on_click(lambda: self.set_rx(not rx.active)) frequency = Knob(title="center frequency", writable=True, value=self.tb.get_sdr_frequency(), digits=10, decimals=0, unit="Hz") frequency.on_change('value', lambda name, old, new: self.set_frequency(new)) bandwidth = Knob(title="filter bandwidth", writable=False, value=self.tb.get_bandwidth(), digits=7, decimals=0, unit="Hz") bandwidth.on_change('value', lambda name, old, new: self.set_bandwidth(new)) reset = Button(label="Reset") def on_reset(): gain.value = run.flowgraph_defaults['sdr_gain'] frequency.value = run.flowgraph_defaults['sdr_frequency'] bandwidth.value = run.flowgraph_defaults['bandwidth'] reset.on_click(on_reset) manual = Panel(title="Manual", child=column( row(rx, gain), row(frequency, bandwidth), reset, )) run_models = {} automated_panels = [] for group, args in run.arg_groups.items(): # TODO: show grouping panel_models = [] for key, arg in args.items(): key = key.replace('-', '_') bokeh_args = arg.get('bokeh', {}) bokeh_args['name'] = key bokeh_args['tags'] = ['args'] if 'default' in arg: bokeh_args['value'] = arg['default'] if 'help' in arg: bokeh_args['title'] = arg['help'] if 'metavar' in arg: bokeh_args['title'] += " (%s)" % (arg['metavar']) type = TextInput if arg.get('type') in (float, int): type = Spinner if 'bokeh' in arg and 'start' in arg[ 'bokeh'] and 'end' in arg['bokeh']: type = Slider if 'step' not in bokeh_args: if arg['type'] == int: bokeh_args['step'] = 1 else: bokeh_args['step'] = 0.01 if arg.get('metavar') == 'Hz': if 'digits' not in bokeh_args: bokeh_args['digits'] = 10 if bokeh_args.get('max'): bokeh_args['digits'] = len("%d" % bokeh_args['max']) type = functools.partial(Knob, decimals=0, unit=arg['metavar']) del bokeh_args['step'] del bokeh_args['tags'] if 'writable' not in bokeh_args: bokeh_args['writable'] = True elif 'choices' in arg: type = Select bokeh_args['options'] = [str(x) for x in arg['choices']] if 'value' in bokeh_args: bokeh_args['value'] = str(bokeh_args['value']) elif arg.get('action') in ('store_true', 'store_false'): type = Select bokeh_args['options'] = [('0', 'False'), ('1', 'True')] bokeh_args['value'] = str(int(bokeh_args['value'])) bokeh_args['tags'] = ['boolean'] + bokeh_args.get( 'tags', []) if group.startswith("mode="): # Make this smarter if we ever have a mode=gal tab bokeh_args['disabled'] = True m = type(**bokeh_args) run_models[key] = m panel_models.append(m) automated_panels.append( Panel(title=group, child=grid(panel_models, ncols=2))) for panel in automated_panels: if panel.title.startswith("mode="): mode_str = panel.title.split('=')[1] run_models['mode'].js_on_change( 'value', CustomJS( args=dict(panel=panel, mode=mode_str), code= """panel.select(Bokeh.require("models/widgets/control").Control).forEach(c => c.disabled = (this.value != mode))""", )) plan_p = Paragraph(sizing_mode="stretch_width", ) load = UploadButton(name="load-settings", accept=".json,application/json", label="Load settings") def on_load(attr, old, new): data = json.loads(base64.b64decode(new)) for key, value in data.items(): if isinstance(run_models[key], Select): value = str(value) run_models[key].value = value load.on_change('value', on_load) save = DownloadButton(label="Save settings", filename="gal_scan_settings.json", mime_type="application/json", data=CustomJS(args=dict(run_models=run_models), code=""" const out = {} for (let k in run_models) { if (!run_models[k].disabled) { out[k] = run_models[k].value const tags = run_models[k].tags if (tags && tags.indexOf("boolean") >= 0) { out[k] = parseInt(out[k]) } } } return JSON.stringify(out, null, 2); """)) start = Button(label="Start scan") def get_args(output_dir): return run.parse_args( [output_dir], { k: int(v.value) if "boolean" in v.tags else v.value for k, v in run_models.items() if not v.disabled }, ) def on_start(): try: output_dir = os.path.join( self.runs_dir, "run_" + datetime.datetime.now().replace(microsecond=0).isoformat()) args = get_args(output_dir) self.enqueue_run(args) except SystemExit: pass start.on_click(on_start) automated = Panel(title="Plan", child=column(Tabs(tabs=automated_panels), plan_p, row(load, save, start))) # TODO: Show cancel buttons for active or queued actions queue_cds = ColumnDataSource(data=self.get_queue_data()) action_column = ActionMenuColumn( field="id", title="Action", menu=[ ("Cancel", "cancel"), ], ) def on_action_menu_click(event): if event.item == "cancel": self.cancel_action(event.value) else: logging.warn("Unknown action clicked: %s", event.item) action_column.on_event(ActionMenuClick, on_action_menu_click) queue_table = SortedDataTable( source=queue_cds, columns=[ TableColumn( field="time", title="Time", formatter=DateFormatter(format="%Y-%m-%d %H:%M:%S"), ), TableColumn(field="user", title="User"), TableColumn(field="name", title="Job"), action_column, ], highlight_field="active", sort_ascending=True, autosize_mode="fit_viewport", aspect_ratio=2, sizing_mode="stretch_width", ) queue = Panel(title="Queue", child=queue_table) results_cds = ColumnDataSource(data={"name": [], "mtime": []}) results_table = SortedDataTable( source=results_cds, columns=[ TableColumn( field="mtime", title="Time", formatter=DateFormatter(format="%Y-%m-%d %H:%M:%S"), ), TableColumn( field="name", title="Name", formatter=HTMLTemplateFormatter( template= '<a href="/runs/<%= value %>/" target="_blank"><%= value %></a>' )), ], autosize_mode="fit_viewport", aspect_ratio=2, sizing_mode="stretch_width", sortable=True, ) results = Panel(title="Results", child=results_table) tabs = Tabs(tabs=[manual, automated, queue, results]) status_p = Paragraph(sizing_mode="stretch_width", ) controls = column(row(azimuth, elevation, rx_power), status_p, tabs, log_table) def get_survey_data(): pointers = { 'ra': [], 'dec': [], 'label': [], 'colour': [], } for o in self.messier: pointers['ra'].append(o['ra']) pointers['dec'].append(o['dec']) pointers['label'].append(o['label']) pointers['colour'].append('') survey = self.active_action.get('survey') out = { 'pointers': pointers, 'status_message': 'Idle', 'plan_message': 'Invalid parameters' } if survey: groups = survey.coord_groups i = 0 for sc, colour in zip(reversed(groups), ('rgb(0, 192, 0)', 'rgb(192, 0, 0)')): sc = sc.icrs for sc in sc: pointers['ra'].append(sc.ra.to(u.degree).value) pointers['dec'].append(sc.dec.to(u.degree).value) pointers['label'].append(str(i + 1)) pointers['colour'].append(colour) i += 1 out['status_message'] = 'Time remaining on current survey: %s' % ( survey.time_remaining.to_datetime()) survey = None try: survey = run.Survey(get_args('bogus')) out['plan_message'] = 'Estimated runtime: %s' % ( survey.time_remaining.to_datetime()) if tabs.tabs[tabs.active] == automated: # TODO: Use the underlying numpy arrays sc = survey.iterator.coords_now.icrs for i, sc in enumerate(sc[:1000]): pointers['ra'].append(sc.ra.to(u.degree).value) pointers['dec'].append(sc.dec.to(u.degree).value) pointers['label'].append(str(i + 1)) pointers['colour'].append('rgb(148,0,211)') except: logging.getLogger('stderr').exception('Invalid parameters') return out sd = get_survey_data() pointers_cds = ColumnDataSource(data=sd['pointers']) def update_pointers(attr, old, new): logging.debug('Updating pointers') sd = get_survey_data() pointers_cds.data = sd['pointers'] plan_p.text = sd['plan_message'] status_p.text = sd['status_message'] update_pointers(None, None, None) log_cds.on_change('data', update_pointers) tabs.on_change('active', update_pointers) for m in run_models.values(): m.on_change('value', update_pointers) skymap = Skymap( height=600, sizing_mode="stretch_height", pointer_data_source=pointers_cds, ) skymap.on_event(Tap, lambda event: self.point(event.x, event.y)) doc.add_root(row( column( skymap, plot.get_figure(), ), controls, ), ) async def update_status(last_status={}): set_x_values() status = self.client.status skymap.latlon = (status['Latitude'], status['Longitude']) skymap.azel = (status['AzPos'], status['ElPos']) if status['CommandAzFlags'] == 'POSITION' or status[ 'CommandElFlags'] == 'POSITION': skymap.targetAzel = (status['CommandAzPos'], status['CommandElPos']) else: skymap.targetAzel = None azimuth.value = status['AzPos'] elevation.value = status['ElPos'] rx_active = status['Sequencer']['Bands'][0]['CommandRX'] if not last_status or rx_active != last_status['Sequencer'][ 'Bands'][0]['CommandRX']: if rx_active: rx.label = "RX enabled" else: rx.label = "RX disabled (50Ω load)" rx.active = rx_active queue_data = self.get_queue_data() if queue_cds.data != queue_data: queue_cds.data = queue_data with os.scandir(self.runs_dir) as it: files = list( sorted(it, reverse=True, key=lambda f: f.stat().st_mtime)) results_data = { "name": [f.name for f in files], "mtime": [int(f.stat().st_mtime * 1000) for f in files], } if results_data != results_cds.data: results_cds.data = results_data last_status.update(status) doc.add_periodic_callback(update_status, 200)
def process_data_samples__tabular(options, name, data, data_types, type_categories, title, with_column_title_rotation=True): """ Create a tabular panel of the data & types Args: options: data: a dictionary of (key, values) data_types: a dictionary of (key, type) indicating special type of ``key`` title: the title of the panel to be displayed Returns: a panel """ image_style = """ img { height:%dpx; width:%dpx; } """ % (options.image_size, options.image_size) template = f""" <div> <style> {image_style} </style> <img src=<%= value %> ></img> </div> """ with_images = False columns = [] for key in data.keys(): type = data_types.get(key) if type is not None and 'BLOB_IMAGE' in type: with_images = True c = TableColumn(field=key, title=key, formatter=HTMLTemplateFormatter(template=template)) else: type_category = type_categories[key] table_kargs = {} if type_category == DataCategory.Continuous: table_kargs['formatter'] = NumberFormatter(format='0,0[.000]') c = TableColumn(field=key, title=key, **table_kargs) columns.append(c) # filter out data filtered_data = filter_large_data(options, data) data_source = ColumnDataSource(filtered_data) if with_column_title_rotation: # custom CSS to slightly rotate the column header # and draw text outside their respective columns # to improve readability. TODO That could be improved div = Div(text=f""" <style> .trw_reporting_table_{name} .slick-header-column {{ background-color: transparent; background-image: none !important; transform: rotate(-10deg) }} .bk-root .slick-header-column.ui-state-default {{ height: 40px; overflow: visible; vertical-align: bottom; line-height: 4.4; }} </style> """) div.visible = False # hide the div to avoid position issues else: div = Div() row_height = options.font_size if with_images: row_height = options.image_size data_table = DataTable( source=data_source, columns=columns, row_height=row_height, #fit_columns=True, css_classes=[f"trw_reporting_table_{name}"]) return Panel(child=column(data_table, div, sizing_mode='stretch_both'), title=title), data_table
data_dict['max'] = data_arr.max(axis=0) data_dict['total'] = data_arr.sum(axis=0) template = """ <div title=<%=(value/total*100).toPrecision(4)%>%> <div style="position: absolute; background: #3477eb; height: calc(<%=value/total%>*100%); width: 100%; bottom: 0"> </div> <div style="position: absolute; height: 100%; width: 100%; background:<%= (function colormax() { if (value == max) { return '#43eb34' } }())%>; color: black"> <%=value %> </div> </div> """ formatter = HTMLTemplateFormatter(template=template) columns = [ TableColumn(field=i, title=i, formatter=formatter) for i in data.columns ] data_table = DataTable(source=ColumnDataSource(data_dict), columns=columns, sizing_mode="scale_both") save(data_table)
def draw_plot(request, years: list = None, countries: list = None, pollutants: list = None, verbosity: int = 0): """ Returns a rendered map with a script and div object. :param request: Django request :param years: The years to of data :param countries: The country code of the regions to be plotted (eg: de, nl, fr) :param pollutants: The pollutant to be plotted (eg: o3, co) :param verbosity: Specifies what level of errors or warnings to be logged (default: 0) :return: Returns Bokeh JSON object """ if request is not None: countries = request.GET.get('countries', None) years = request.GET.get('years', None) pollutants = request.GET.get('pollutants', None) verbosity = request.GET.get('verbosity', 0) # get Target pollutants t_pollutants = [ x.get('pollutant_id') for x in Target.objects.filter( measurement='calendar_year').values('pollutant_id') ] # get the Observation station readings pollutant names for selected target-relevant pollutants if pollutants is None: pollutants = t_pollutants else: pollutants_lookup = { k: v.key for k, v in Pollutant.get_observation_pollutants().items() if v.key in pollutants } pollutants = list(pollutants_lookup.values()) if countries is None: countries = EU_ISOCODES if years is None: years = [] u_years_rs = ObservationStationReading.objects.filter( country_code__in=countries, validity=1, pollutant__in=map( str.upper, pollutants)).values('date_time__year').distinct() for item in u_years_rs: years.append(list(item.values())[0]) years.sort() # get data for countries for selected pollutants annual_dict = annual(request, years=years, countries=countries, pollutants=pollutants, verbosity=verbosity) annual_dict = json.loads(annual_dict.content.decode()) # create a dataframe of actual pollutant averages per year, country and pollutant annual_df = pd.DataFrame() for c, years_dict in annual_dict.items(): xdf = pd.DataFrame(years_dict).reset_index().rename( columns={'index': 'pollutant'}) xdf.insert(0, 'country', c) annual_df = annual_df.append(xdf) annual_df = annual_df.reset_index(drop=True) # get targets t_df = Pollutant.get_targets_df(years=[years[-1]], pollutants=pollutants) t_df = t_df[t_df.measurement_id == 'calendar_year'] t_df = t_df[['country', 'pollutant_id', 'value']].rename \ (columns={'pollutant_id': 'pollutant', 'value': 'target_value'}) # merge targets with actuals annual_df = annual_df.merge(t_df) # add vs. Target Columns def per_fmt(s): if math.isnan(s): return '-' return f"{s:0.1%}" # for each year, add a comparison vs target column for y in years: idx = list(annual_df.columns).index(str(y)) new_col = annual_df[str(y)] / annual_df['target_value'] new_col = new_col.apply(per_fmt) annual_df.insert(idx + 1, f"{y} vs. Target", new_col) # format nan values def fmt(s): rv = round(s, 2) if math.isnan(rv): rv = '-' return rv for y in years: annual_df[str(y)] = annual_df[str(y)].apply(fmt) vsTarget_template = """ <div style="text-align:right; color:<%= (function colorfromfloat(){ if(parseFloat(value.substring(0, value.length-1))<100){ return("green")} else{return("red")} }()) %>; "> <%= value %></div> """ vsTarget_formater = HTMLTemplateFormatter(template=vsTarget_template) source = ColumnDataSource(annual_df) val_template = """<div style="text-align:right;"><%= value %></div>""" val_formatter = HTMLTemplateFormatter(template=val_template) columns = [ TableColumn(field="country", title="Country"), TableColumn(field="pollutant", title="Pollutant"), TableColumn(field='target_value', title="Target", formatter=val_formatter) ] for y in years: columns.append( TableColumn(field=str(y), title=str(y), formatter=val_formatter)) columns.append( TableColumn(field=f"{y} vs. Target", title=f"{y} vs. Target", formatter=vsTarget_formater)) data_table = DataTable(source=source, columns=columns, width=800, height=400, index_position=None, sizing_mode='stretch_both') # jupyter notebook # return data_table # django data_table = json_item(data_table) return JsonResponse(data_table)
def run_make_table(creds): if creds.get('env') == 'dev': csvs_file_location = './dev_csv' else: csvs_file_location = 's3://graycannon.com/csvs' df = pd.read_csv('{}/country_table.csv'.format(csvs_file_location)) df2 = pd.read_csv('{}/locale_table.csv'.format(csvs_file_location)) base = pd.read_csv('{}/base.csv'.format(csvs_file_location)) df['charts_page'] = './chart_pages/country_' + df['country_region'] + '.html' df2['charts_page'] = './chart_pages/locale_' + df2['locale'] + '.html' original_source1 = ColumnDataSource(data=df) source1 = ColumnDataSource(data=df) original_source2 = ColumnDataSource(data=df2) source2 = ColumnDataSource(data=df2) button = Button(label="Download", button_type="success", width_policy="max") button.js_on_click(CustomJS(args=dict(source=source1), code=open(join(dirname(__file__), "download.js")).read())) button2 = Button(label="Download", button_type="success", width_policy="max") button2.js_on_click(CustomJS(args=dict(source=source2), code=open(join(dirname(__file__), "download.js")).read())) columns = [ TableColumn(field="country_region", title="Country/Region"), TableColumn(field="current_day", title="Confirmed Cases To {}".format(base['day'].max()), formatter=NumberFormatter(format="0,0")), TableColumn(field="new_cases", title="New Cases Current Day", formatter=NumberFormatter(format="0,0")), TableColumn(field="peak_new", title="Peak New Cases", formatter=NumberFormatter(format="0,0")), TableColumn(field="since_peak_new", title="Days Since Peak", formatter=NumberFormatter(format="0,0")), TableColumn(field="growth_rate", title="Daily Growth Rate", formatter=NumberFormatter(format="0,0.00")), TableColumn(field="growth_factor", title="Daily Growth Factor", formatter=NumberFormatter(format="0,0.00")), TableColumn(field="growth_rate_week", title="Weekly Growth Rate", formatter=NumberFormatter(format="0,0.00")), TableColumn(field="growth_factor_week", title="Weekly Growth Factor", formatter=NumberFormatter(format="0,0.00")), TableColumn(field="charts_page", title="Link to Charts", formatter=HTMLTemplateFormatter(template='<a href="<%= charts_page%>" target="_blank"><%= country_region %> Charts</a>')) ] columns2 = columns.copy() columns2[0] = TableColumn(field="locale", title="Province/State") columns2[9] = TableColumn(field="charts_page", title="Link to Charts", formatter=HTMLTemplateFormatter(template='<a href="<%= charts_page%>" target="_blank"><%= locale %> Charts</a>')) data_table = DataTable(source=source1, columns=columns, width=1700, index_position=None) data_table2 = DataTable(source=source2, columns=columns2, width=1700, index_position=None) reset_button = Button(label="Reset Table", button_type="success", width_policy="min", height_policy="max") reset_button2 = Button(label="Reset Table", button_type="success", width_policy="min", height_policy="max") country_list = df['country_region'].unique().tolist() country_list_lower = [x.lower() for x in country_list] country_options = country_list + country_list_lower country_search = AutocompleteInput(title="Country:", completions=country_options) locale_list = df2['locale'].unique().tolist() locale_list_lower = [x.lower() for x in locale_list] locale_options = locale_list + locale_list_lower locale_search = AutocompleteInput(title="Province/State:", completions=locale_options) search_js = """ var data = source.data; var originalData = orig.data; var f = cb_obj.value; for (var key in data) { data[key] = []; for (var i = 0; i < originalData[breakdown].length; ++i) { if (originalData[breakdown][i].toLowerCase() === f.toLowerCase()) { data[key].push(originalData[key][i]); } } } console.log('originalData', originalData); console.log('data', data); source.change.emit(); """ reset_js = """ console.log('click'); search.value = ''; source.data = JSON.parse(JSON.stringify(orig.data)); source.change.emit(); """ callback = CustomJS(args=dict(source=source1, orig=original_source1, breakdown='country_region', target_object=data_table), code=search_js) reset_callback = CustomJS(args=dict(source=source1, orig=original_source1, search=country_search, target_object=data_table), code=reset_js) country_search.js_on_change('value', callback) reset_button.js_on_click(reset_callback) callback2 = CustomJS(args=dict(source=source2, orig=original_source2, breakdown='locale', target_object=data_table), code=search_js) reset_callback2 = CustomJS(args=dict(source=source2, orig=original_source2, search=locale_search, target_object=data_table), code=reset_js) locale_search.js_on_change('value', callback2) reset_button2.js_on_click(reset_callback2) page_layout = layout( [country_search, reset_button], [data_table], [button], [locale_search, reset_button2], [data_table2], [button2] ) object_key = 'covid_tables.html' filename = '/tmp/{}'.format(object_key) output_file(filename, title='Covid Data Tables') save(page_layout) write_html_to_s3(filename, object_key, creds) os.remove(filename)
def Market_map(): df = pd.read_csv('./data/App_data/AQ_EM_tse_final_profibility_1.csv', encoding='utf-8') df['yyyymm'] = df['yyyymm'].astype(str) df['company_name'] = df.company.astype(int).astype( str) + ' ' + df.company_abbreviation year = Select(title='年份:', value='201812', options=df.yyyymm.drop_duplicates().sort_values().astype( str).to_list(), width=100) col_type = Select(title='分類方式:', value='產業', options=['產業', '新產業', '市值排名'], width=100) sort_type = Select(title='排序方式:', value='市值', options=['市值', 'eps', '負債比', 'working capital/TA'], width=100) color_type = Select(title='上色方式(前10%)', value='市值', options=['市值', '資產', 'eps'], width=100) input_dict = { '產業': 'tse_industry_name', '市值': 'market_value', '資產': 'asset', '新產業': 'new_industry_code', '市值排名': 'value_rank', '負債比': 'debt ratio', 'working capital/TA': 'working capital/TA', 'eps': 'eps' } def get_data(): select_year = year.value col = input_dict[col_type.value] sort = input_dict[sort_type.value] color = input_dict[color_type.value] data = df.query('yyyymm==@select_year') if col == 'value_rank': data = data.dropna(subset=['market_value']) data['rank_h'] = (data['market_value'].rank(ascending=False) / 100).astype(int) rmax = data['rank_h'].max() def cal_vrank(x): if x == 0: return '0~100' elif x == rmax: return f'{rmax*100}名以上' else: return f'{x*100}名~{(x+1)*100}名' data['value_rank'] = data['rank_h'].apply(cal_vrank) del data['rank_h'] else: data = data.dropna(subset=[col, sort, color]) sorting = data.sort_values(sort, ascending=False).groupby([col]).agg( {'company_name': list}) if col != 'value_rank': sorting['co_num'] = sorting['company_name'].apply(lambda x: len(x)) sorting = sorting.sort_values('co_num', ascending=False)[['company_name']] table = pd.DataFrame.from_dict( sorting.T.to_dict('records')[0], 'index').T.fillna('') source_table = ColumnDataSource(table) top_co = data[ data[color] > data[color].quantile(0.9)]['company_name'].to_list() source_color = ColumnDataSource(data={'top_co': top_co}) return source_table, source_color source_table, source_color = get_data() template='<div style="background:<%=(function colorfromint(){'+\ f'if({str(source_color.data["top_co"])}.indexOf(value) > -1)'+\ '{return("#ffb3b3")}else{return("white")}}()) %>; color: black"> <%= value %></div>' formatter = HTMLTemplateFormatter(template=template) columns = [] for colnames in source_table.data.keys(): if colnames != 'index': columns.append( TableColumn(field=colnames, title=colnames, formatter=formatter)) table = DataTable(source=source_table, columns=columns, width=2500, height=1000, editable=True) def update(attr, old, new): new_source_table, new_source_color = get_data() new_template = '<div style="background:<%=(function colorfromint(){'+\ f'if({str(new_source_color.data["top_co"])}.indexOf(value) > -1)'+\ '{return("#ffb3b3")}else{return("white")}}()) %>; color: black"> <%= value %></div>' new_formatter = HTMLTemplateFormatter(template=new_template) new_columns = [] for colnames in new_source_table.data.keys(): if colnames != 'index': new_columns.append( TableColumn(field=colnames, title=colnames, formatter=new_formatter)) table.source = new_source_table table.columns = new_columns year.on_change('value', update) col_type.on_change('value', update) sort_type.on_change('value', update) color_type.on_change('value', update) hspace = Spacer(width=20) input = row(year, hspace, col_type, hspace, sort_type, hspace, color_type) final_layout = column(input, table) return Panel(child=column(Spacer(height=35), final_layout), title='資本市場地圖')
pandata.fillna('None', inplace=True) # just replace missing values with zero source = ColumnDataSource(pandata) SIZES = list(range(6, 22, 3)) columns = [ TableColumn(field="HostnameIP", title="Address", width=450), TableColumn(field="Malware", title="Malware"), TableColumn(field="Compromise", title="Compromise"), TableColumn(field="Lookup:Success", title="Success"), TableColumn(field="Lookup:IOCScanned", title="IOCScanned"), TableColumn(field="Lookup:HashScanned", title="HashScanned"), TableColumn(field="Lookup:Subnet", title="Subnet"), TableColumn(field='HostId', title='Result', formatter=HTMLTemplateFormatter( template='<a href="http://localhost:5000/host-result/<%= value %>" target="_blank">#<%= value %></a>')) ] data_table = DataTable(source=source, columns=columns, fit_columns=True) columns = sorted(pandata.columns) filtered_columns = [c for c in columns if 'Hostname' not in c and 'HostId' not in c] discrete = [x for x in columns if pandata[x].dtype == object] continuous = [x for x in columns if x not in discrete] quantileable = [x for x in continuous if len(pandata[x].unique()) > 1] def create_figure(): # args = curdoc().session_context.request.arguments # with open('args.txt', 'w') as the_file: # the_file.write(str(curdoc().session_context.request.arguments['batchid'])) # the_file.write(str(args))
connection_time=connection_time, page_link=page_links, ) source = ColumnDataSource(data) button = Button(label="Foo", button_type="success") columns = [ TableColumn(field="session_id", title="Session ID"), TableColumn(field="cpu_usage", title="CPU Usage"), TableColumn(field="memory_usage", title="Memory Usage"), TableColumn(field="spawn_time", title="Spawn Time"), TableColumn(field="connection_time", title="Connection Time"), TableColumn( field="page_link", title="Page Link", formatter=HTMLTemplateFormatter( template='<a href="<%= value %>" target="_blank">see visualization here</a>' ), width=600, ), ] data_table = DataTable( source=source, columns=columns, width=400, height=280, selectable="checkbox" ) def modify_doc(): selected_indices = source.selected.indices session_infos = source.data for indice in selected_indices: print(session_infos["session_id"][indice])
def app(): buff, buff2 = st.beta_columns([2, 3]) #buff.markdown('<img style="float: left;" src="https://virtual.usal.edu.ar/branding/themes/Usal_7Julio_2017/images/60usalpad.png" />', unsafe_allow_html=True) st.markdown("""<style> .grid-canvas{font-size:14px;} .slick-header-columns{font-size:16px;font-weight:500;color:#008357;} </style> """, unsafe_allow_html=True) buff.markdown( "<h3 style='text-align: left; color: #008357;'>Grabaciones</h3>", unsafe_allow_html=True) buff.markdown( "<h3 style='text-align: left; color: #008357;'>Learn, Moodle y salas Collaborate</h3>", unsafe_allow_html=True) SHEET_ID = '1KTE7TM2xclv6PM7blUyApXLopBUvYWY9gbWWlJKBXwI' df = pd.read_csv('https://docs.google.com/spreadsheets/d/' + SHEET_ID + '/export?format=csv&gid=1396712') df = df.sort_values(by=['SessionOwner']) df1 = pd.read_csv( 'https://docs.google.com/spreadsheets/d/1KTE7TM2xclv6PM7blUyApXLopBUvYWY9gbWWlJKBXwI/export?format=csv&gid=249253768' ) #antes = pd.read_csv('https://docs.google.com/spreadsheets/d/1KTE7TM2xclv6PM7blUyApXLopBUvYWY9gbWWlJKBXwI/export?format=csv&gid=1158662089') if st.checkbox('Ver Cronograma de borrado'): df1.index = [""] * len(df1) st.table(df1) #gigasantes=antes['StorageUsageGigabytes'].sum()/1000000000 gigas = df['StorageUsageGigabytes'].sum() / 1000000000 times3 = df.index graba = len(times3) #times33=antes.index #graba2=len(times33) #st.sidebar.markdown("<h3 style='text-align: left; color: black;font-weight:500;'>Almacenamiento y cantidad</h3>", unsafe_allow_html=True) #st.sidebar.markdown("<hr>", unsafe_allow_html=True) #st.sidebar.write('Semanal: ',round(gigas,1)," Gbytes") #st.sidebar.write('Semanal: ',graba) #df = pd.read_csv('/mydrive/MyDrive/multiapps/bbc204.csv') # selecting rows based on condition options = ['ALEJANDRA.LAMBERTI', 'josemarcucci'] # selecting rows based on condition df = df.loc[~df['SessionOwner'].isin(options)] countries = df['SessionOwner'].unique() country = buff.selectbox('Usuario BBC', countries) df[df['SessionOwner'] == country] #option = st.selectbox("Seleccionar Unidad", options=list(CHOICES.keys()), format_func=format_func) #st.write(f"Seleccionaste {format_func(option)}" ) #column = format_func(option) above_352 = df["SessionOwner"] == country bool_series = df[above_352]["SessionOwner"].str.startswith(country, na=False) time = pd.DatetimeIndex(df[above_352][bool_series]['RecordingDuration']) times1 = time.hour * 60 + time.minute + time.second / 60 times = times1.values.sum() #df[above_352][bool_series]['StorageUsageGigabytes']=df[above_352][bool_series]['StorageUsageGigabytes'].replace(",", "") #df[above_352][bool_series]['StorageUsageGigabytes']=df[above_352][bool_series]['StorageUsageGigabytes'].astype(int) gigast = df[above_352][bool_series]['StorageUsageGigabytes'].sum( ) / 1000000000 times3 = df[above_352][bool_series].index aulas = len(times3) timee = pd.DatetimeIndex(df['RecordingDuration']) timees1 = (timee.hour * 60 + timee.minute + timee.second / 60) timees = timees1.values.sum() st.sidebar.markdown( "<h3 style='text-align: left; color: black;font-weight:500;'>Almacenamiento y cantidad</h3>", unsafe_allow_html=True) st.sidebar.write('Total: ', round(gigas, 1), " Gbytes") st.sidebar.write('Total grabaciones: ', graba) #st.sidebar.write('Minutos grabados: ',timees) df['RecordingCreated'] = pd.to_datetime( df['RecordingCreated']).dt.strftime('%y/%m/%d') #df.style.format({"RecordingCreated": lambda t: t.strftime("%d-%m-%Y")}) maxValue = df['RecordingCreated'].max() minValue = df['RecordingCreated'].min() st.write('Período:', minValue, ' al ', maxValue) st.write('Grabaciones: ', aulas) #st.write('Minutos grabados: ',round(times,1)) from bokeh.models.widgets import Div #if st.button('Go to Streamlit'): #js = "window.open('https://www.streamlit.io/')" # New tab or window #js = "window.location.href = 'https://www.streamlit.io/'" # Current tab #html = '<img src onerror="{}">'.format(js) #div = Div(text=html) #st.bokeh_chart(div) if st.checkbox('Mostrar Grabaciones de la UA'): #df[above_352][bool_series][['RecordingCreated','SessionOwner','SessionName','RecordingDuration','StorageUsageGigabytes']].index = [""] * len(df[above_352][bool_series][['RecordingCreated','SessionOwner','SessionName','RecordingDuration','StorageUsageGigabytes']]) todas = df[above_352][bool_series] todas.index = [""] * len(todas) todas = todas.sort_values(by=['RecordingCreated']) todas['RecordingCreated'] = pd.to_datetime( todas['RecordingCreated']).dt.strftime('%d-%m-%y') #todas['RecordingCreated']=todas['RecordingCreated'].apply(lambda _: datetime.strptime(_,"%m/%d/%Y, %H:%M:%S")) #datefmt = bokeh.models.DateFormatter(format="%d/%m/%Y") #st.table(todas[['RecordingCreated','SessionName','RecordingDuration','StorageUsageGigabytes']]) df991 = pd.DataFrame({ "Fecha": todas['RecordingCreated'], "Nombre": todas['SessionName'], "Autor": todas['SessionOwner'], "Duracion": todas['RecordingDuration'], "Tamaño": todas['StorageUsageGigabytes'] }) cds = ColumnDataSource(df991) columns = [ TableColumn(field="Fecha", title="Fecha", width=100), TableColumn( field="Nombre", title="Nombre", formatter=HTMLTemplateFormatter(template='<%= value %>'), width=500), TableColumn( field="Autor", title="Autor", formatter=HTMLTemplateFormatter(template='<%= value %>'), width=200), TableColumn( field="Duracion", title="Duracion", formatter=HTMLTemplateFormatter(template='<%= value %>'), width=100), TableColumn( field="Tamaño", title="Tamaño", formatter=HTMLTemplateFormatter(template='<%= value %>'), width=100), ] p3 = DataTable(source=cds, columns=columns, css_classes=["my_table"], index_position=None, width=1100, height=550) st.bokeh_chart(p3) if st.checkbox('Buscar Grabaciones de la UA'): buff8, buff2 = st.beta_columns([2, 3]) #df[above_352][bool_series][['RecordingCreated','SessionOwner','SessionName','RecordingDuration','StorageUsageGigabytes']].index = [""] * len(df[above_352][bool_series][['RecordingCreated','SessionOwner','SessionName','RecordingDuration','StorageUsageGigabytes']]) todas = df[above_352][bool_series] todas.index = [""] * len(todas) todas = todas.sort_values(by=['RecordingCreated']) todas['RecordingCreated'] = pd.to_datetime( todas['RecordingCreated']).dt.strftime('%d-%m-%y') solo = df[above_352][bool_series] solo = solo.sort_values(by=['SessionName']) solo = solo['SessionName'].unique() reinput = buff8.selectbox('Curso', solo) if reinput: df88 = todas[todas['SessionName'] == reinput] df99 = pd.DataFrame({ "Fecha": df88['RecordingCreated'], "Nombre": df88['SessionName'], "links": df88['RecordingLink'] }) cds = ColumnDataSource(df99) columns = [ TableColumn( field="Fecha", title="Fecha", formatter=HTMLTemplateFormatter(template='<%= value %>'), width=200), TableColumn( field="Nombre", title="Nombre", formatter=HTMLTemplateFormatter(template='<%= value %>'), width=300), TableColumn( field="links", title="Grabacion", formatter=HTMLTemplateFormatter( template= '<a href="<%= value %>"target="_blank"><%= value %></a>' ), width=400), ] p = DataTable(source=cds, columns=columns, css_classes=["my_table"], index_position=None, width=1000, height=250) st.bokeh_chart(p) #st.table(todas[['RecordingCreated','SessionName','RecordingDuration','StorageUsageGigabytes']]) if st.checkbox('Mostrar Todas las Grabaciones'): #df[above_352][bool_series][['RecordingCreated','SessionOwner','SessionName','RecordingDuration','StorageUsageGigabytes']].index = [""] * len(df[above_352][bool_series][['RecordingCreated','SessionOwner','SessionName','RecordingDuration','StorageUsageGigabytes']]) todas1 = df todas1.index = [""] * len(todas1) todas1 = todas1.sort_values(by=['RecordingCreated']) todas1['RecordingCreated'] = pd.to_datetime( todas1['RecordingCreated']).dt.strftime('%d-%m-%y') df992 = pd.DataFrame({ "Fecha": todas1['RecordingCreated'], "Nombre": todas1['SessionName'], "Autor": todas1['SessionOwner'], "Duracion": todas1['RecordingDuration'], "Tamaño": todas1['StorageUsageGigabytes'] }) cds = ColumnDataSource(df992) columns = [ TableColumn( field="Fecha", title="Fecha", formatter=HTMLTemplateFormatter(template='<%= value %>'), width=100), TableColumn( field="Nombre", title="Nombre", formatter=HTMLTemplateFormatter(template='<%= value %>'), width=500), TableColumn( field="Autor", title="Autor", formatter=HTMLTemplateFormatter(template='<%= value %>'), width=200), TableColumn( field="Duracion", title="Duracion", formatter=HTMLTemplateFormatter(template='<%= value %>'), width=100), TableColumn( field="Tamaño", title="Tamaño", formatter=HTMLTemplateFormatter(template='<%= value %>'), width=100), ] p2 = DataTable(source=cds, columns=columns, css_classes=["my_table"], index_position=None, width=1100, height=550) st.bokeh_chart(p2)