def _create_app(): player_select_widget = pn.widgets.Select( options=list(_get_epl_strikers_df()["player_name"].unique()), value="Bruno Fernandes", min_width=1600, max_width=1800, ) # assign css class to achieve better design granularity player_select_row = pn.Row( pn.pane.Str("Choose A Player for Analysis:", sizing_mode="fixed"), player_select_widget, align="center", css_classes=["player_select_row"], ) # Panel HTML elements can take a 'style' parameter directly. # You could alternatively assign a css class as above and include the css code in raw_css title_html_pane = pn.pane.HTML( """ <h1>Panel Soccer Analytics Dashboard</h1> """, style={ "color": "white", "width": "90%", "text-align": "center" }, ) # bind the 'player_select_widget' to our functions above bound_player_png_image_pane = pn.bind(_get_and_display_player_image, player=player_select_widget) plot_horizontal_bar_pane = pn.bind(_plot_horizontal_bar, player=player_select_widget) bound_plotly_line_plot_pane = pn.bind(_plot_line_plot, player=player_select_widget) bound_plotly_scatter_plot_pane = pn.bind(_plot_scatter_plot, player=player_select_widget) # create a new gridspec with 14 columns and 12 rows gspec = pn.GridSpec(ncols=14, nrows=12, sizing_mode="stretch_both", css_classes=["gspec_container"]) # place application elements in the grid, using pn.Spacer() for improved layout spacing and # control gspec[0, :14] = title_html_pane gspec[1, :14] = player_select_row gspec[3:6, 1:3] = bound_player_png_image_pane gspec[2:7, 3] = pn.Spacer() gspec[2:7, 4:14] = plot_horizontal_bar_pane gspec[7:10, 0:7] = bound_plotly_line_plot_pane gspec[7:10, 7:14] = bound_plotly_scatter_plot_pane gspec[11, 0:14] = pn.Row(pn.Spacer(), CSS_PANE) return gspec
def panel(self): result = bootstrap price_slider = pn.widgets.RangeSlider.from_param( self.param.price_slider, step=10000, format='0.0a') result.sidebar.append(price_slider) result.sidebar.append(self.param.rooms_slider) result.sidebar.append(self.param.bathrooms_slider) result.sidebar.append(self.param.type) result.sidebar.append(self.param.transit_time) image_format = r'<div> <img src="<%= value %>" height="70" alt="<%= value %>" width="70" style="float: left; margin: 0px 15px 15px 0px;" border="2" ></img> </div>' tabulator_formatters = { 'price': NumberFormatter(format='$0,0'), 'size': NumberFormatter(format='0,0 sqft'), 'photo': HTMLTemplateFormatter(template=image_format) } df_widget = pn.widgets.Tabulator(self.filter_df(), pagination='remote', page_size=10, formatters=tabulator_formatters, sizing_mode='scale_both') df_widget.add_filter(self.param.price_slider, 'price') df_widget.add_filter(self.param.rooms_slider, 'bedrooms') # df_pins = pn.widgets.Tabulator(self.distance_df(), pagination='remote', page_size=10, sizing_mode='scale_both') layout = pn.Row( pn.Card(pn.bind(self.location, x=self.stream.param.x, y=self.stream.param.y), title="Map", sizing_mode='stretch_height'), pn.Column( pn.Card(df_widget, title="Properties", sizing_mode='scale_both'))) result.sidebar.append( pn.Card(pn.bind(self.distance_df, x=self.stream.param.x, y=self.stream.param.y), title="Pins", sizing_mode='scale_both')) bootstrap.main.append(layout) bootstrap.main.append(pn.Card(self.details_area, title='Details')) return result
def create_dyntseries(): trange = np.arange( datetime.datetime(2011, 1, 1), utcnow, datetime.timedelta(days=1), ) dyntseries = hv.DynamicMap(plot_tseries, kdims=["Dataset", "TimeRange", "Stdnames"]) dyntseries = dyntseries.redim.values( Dataset=dsnames, TimeRange=trange, Stdnames=valid_stdnames, ) dyntseries.opts(width=500, framewise=True) dyntseries = hv.DynamicMap( pn.bind( plot_tseries, dataset=wds_menu, timerange=wds_date, stdname=wstdname_menu, ), ) return dyntseries
def test_overlay_params_bind_linked_stream(self): tap = Tap() def test(x): return Curve([1, 2, 3]) * VLine(x or 0) dmap = DynamicMap(pn.bind(test, x=tap.param.x)) plot = bokeh_renderer.get_plot(dmap) tap.event(x=1) _, vline_plot = plot.subplots.values() assert vline_plot.handles['glyph'].location == 1
def hvplot_stack( da, x="lon", y="lat", z="date", vmin=None, vmax=None, cmap="seismic_wide_y_r", twoway=True, vm=None, height=400, width=600, ): """Make a 2-panel interactive plot with clickable timeseries""" import panel as pn import holoviews as hv def get_timeseries(x, y): return da.sel(lon=x, lat=y, method="nearest").hvplot(z) # pn.extension() vmin, vmax = _get_vminmax(da[-1], vm=vm, vmin=vmin, vmax=vmax, twoway=twoway) image, select = da.hvplot( x, y, # widgets={z: pn.widgets.Select}, widgets={z: pn.widgets.DiscreteSlider}, cmap=cmap, clim=(vmin, vmax), height=height, width=width, ) stream = hv.streams.Tap(source=image.object, x=da[x][0].item(), y=da[y][0].item()) return pn.Column( image, select, pn.bind(get_timeseries, x=stream.param.x, y=stream.param.y))
def create_dyndsmap(): trange = np.arange( datetime.datetime(2011, 1, 1), utcnow, datetime.timedelta(days=1), ) dyndsmap = hv.DynamicMap(plot_dsmap, kdims=["Stdnames", "TimeRange"]) dyndsmap = dyndsmap.redim.values(Stdnames=valid_stdnames, TimeRange=trange) dyndsmap = hv.DynamicMap( pn.bind( plot_dsmap, stdname=wstdname_menu, timerange=wstdname_date, ), ) return dyndsmap
def mark_table_selection(tables): def plot(*args): xs = [ table.value.index[x] for xs, table in zip(args, tables) for x in xs ] return hv.Overlay([ hv.VLine(x).opts( backend='bokeh', line_dash='dashed', ) for x in xs ]) tables = list(tables) streams = [table.param.selection for table in tables] bound = pn.bind(plot, *streams) dmap = hv.DynamicMap(bound).opts(framewise=True) return dmap
document.getElementsByClassName('{icon}')[0].childNodes[1].innerHTML = '{str(val)}'; document.getElementsByClassName('{icon}')[0].childNodes[1].style.backgroundColor = 'red'; console.log('ico2'); </script> """ else: s = f""" <script> console.log('ico1'); document.getElementsByClassName('{icon}')[0].childNodes[1].innerHTML = ''; document.getElementsByClassName('{icon}')[0].childNodes[1].style.backgroundColor = '#2f2f31'; console.log('ico2'); </script> """ icon_numbers.object = s pn.bind(get_counting, sli.param.value, watch=True) col2 = pn.Column(header, pn.Spacer(sizing_mode='stretch_width', height=5, css_classes = ['header_bar']), sub_header, gspec, sizing_mode='stretch_width') # pn.state.onload(load) pn.Row(col,col2, margin=0, sizing_mode='stretch_both').servable()
window=30, sigma=10, view_fn=mpl_plot): avg = data[variable].rolling(window=window).mean() residual = data[variable] - avg std = residual.rolling(window=window).std() outliers = (np.abs(residual) > std * sigma) return view_fn(avg, avg[outliers]) pn.extension() pn.interact(find_outliers) text = "<br>\n# Room Occupancy\nSelect the variable, and the time window for smoothing" kw = dict(window=(1, 60), variable=sorted(list(data.columns)), sigma=(1, 20)) i = pn.interact(find_outliers, **kw) p = pn.Row(i[1][0], pn.Column(text, i[0][0], i[0][1])) variable = pnw.RadioButtonGroup(name='variable', value='Temperature', options=list(data.columns)) window = pnw.IntSlider(name='window', value=10, start=1, end=60) reactive_outliers = pn.bind(find_outliers, variable, window, 10) widgets = pn.Column("<br>\n# Room occupancy", variable, window) occupancy = pn.Row(reactive_outliers, widgets) occupancy.servable()
def baseline(self): self.peak_currents = np.zeros(len(self.dfs)) #eak_left = -0.34 #eak_right = -0.28 #eft_limit = 30 steppp = self.dfs[0]["Potential"][0] - self.dfs[0]["Potential"][1] first_point = self.dfs[0]["Potential"].iloc[0] last_point = self.dfs[0]["Potential"].iloc[-1] peak_left_slider = pnw.FloatSlider(name='Peak Left', value=-0.35, start=last_point, end=first_point, step=0.01) peak_right_slider = pnw.FloatSlider(name='Peak Right', value=-0.25, start=last_point, end=first_point, step=0.01) limit_left_slider = pnw.IntSlider(name='Limit Left', value=10, start=0, end=len(self.dfs[0]["Potential"]) - int(0.1 / steppp)) limit_right_slider = pnw.IntSlider(name='Limit Right', value=10, start=0, end=len(self.dfs[0]["Potential"]) - int(0.1 / steppp)) time_step_slider = pnw.IntSlider(name='Time Step', value=0, start=0, end=len(self.dfs) - 1) @pn.depends(time_step_slider, peak_left_slider, peak_right_slider, limit_left_slider, limit_right_slider) def max_current(time_stamp=time_step_slider.param.value, a=peak_left_slider, b=peak_right_slider, c=limit_left_slider, d=limit_right_slider): return pn.pane.Markdown( "peak current [A]: " + str("{:.3e}".format(self.peak_currents[0]))) def update_sliders(time_stamp): peak_left_slider.start = float( decimal.Decimal(limit_left_slider.value * steppp + self.dfs[time_stamp]["Potential"].iloc[-1] + steppp).quantize(decimal.Decimal('.01'), rounding=decimal.ROUND_UP)) #print(limit_left_slider.value*steppp+dfs[time_stamp]["Potential"].iloc[-1]) #print(float(decimal.Decimal(limit_left_slider.value*steppp+dfs[time_stamp]["Potential"].iloc[-1]+steppp).quantize(decimal.Decimal('.01'), rounding=decimal.ROUND_DOWN))) #print(dfs[time_stamp]["Potential"].iloc[-(limit_left_slider.value+1)]) peak_left_slider.end = peak_right_slider.value if (peak_left_slider.value > peak_left_slider.end): peak_left_slider.value = peak_left_slider.end if (peak_left_slider.value < peak_left_slider.start): peak_left_slider.value = peak_left_slider.start peak_right_slider.end = round( +self.dfs[time_stamp]["Potential"].iloc[0] - limit_right_slider.value * steppp, 2) if (peak_right_slider.value > peak_right_slider.end): peak_right_slider.value = peak_right_slider.end if (peak_right_slider.value < peak_right_slider.start): peak_right_slider.value = peak_right_slider.start max_current.value = self.peak_currents[time_stamp] def interact_frame(time_stamp=0, peak_left=peak_left_slider.value, peak_right=peak_right_slider.value, left_limit=limit_left_slider.value, right_limit=limit_right_slider.value): peak_removed = [None] * len(self.dfs) removed = [None] * len(self.dfs) fit = [None] * len(self.dfs) baseline = [None] * len(self.dfs) for i, meas in enumerate(self.dfs): peak_removed[i] = self.dfs[i].loc[((self.dfs[i].Potential <= peak_left)) | (self.dfs[i].Potential >= peak_right ),\ ['Potential', 'Diff']] removed[i] = pd.concat([ self.dfs[i].iloc[0:right_limit], self.dfs[i].iloc[-left_limit:] ]) #['Potential', 'Diff']) baseline[i] = pd.concat([ peak_removed[i].iloc[right_limit:-left_limit], peak_removed[i].iloc[right_limit:-left_limit] ]) fit[i] = np.polynomial.polynomial.polyfit( peak_removed[i]['Potential'][right_limit:-left_limit], peak_removed[i]['Diff'][right_limit:-left_limit], 1) for j in self.dfs[i].index: self.dfs[i].at[j, 'Fit'] = np.polynomial.polynomial.polyval( self.dfs[i].loc[j]['Potential'], fit[i]) if (self.dfs[i].at[j, 'Potential'] > peak_left) and ( self.dfs[i].at[j, 'Potential'] < peak_right): self.dfs[i].at[ j, 'Peak'] = abs(self.dfs[i].loc[j]['Diff'] - self.dfs[i].loc[j]['Fit']) self.peak_currents[i] = self.dfs[i]['Peak'].max() plot_title = 'Time' + str(self.time_stamps[time_stamp]) measurement_list = [ hv.Points(data=self.dfs[time_stamp], kdims=[('Potential', 'Potential [V]'), ('Diff', 'Current [A]')], vdims=[]) ] fit_list = [ hv.Points(data=self.dfs[time_stamp], kdims=[('Potential', 'Potential [V]'), ('Fit', 'Current [A]')], vdims=[]) ] fit_list2 = [ hv.Points(data=peak_removed[time_stamp], kdims=[('Potential', 'Potential [V]'), ('Diff', 'Current [A]')], vdims=[]).opts(color="r") ] fit_list3 = [ hv.Points(data=removed[time_stamp], kdims=[('Potential', 'Potential [V]'), ('Diff', 'Current [A]')], vdims=[]).opts(color="y") ] fit_list4 = [ hv.Points(data=baseline[time_stamp], kdims=[('Potential', 'Potential [V]'), ('Diff', 'Current [A]')], vdims=[]).opts(color="purple") ] overlay = hv.Overlay(measurement_list + fit_list + fit_list2 + fit_list3 + fit_list4) overlay = overlay.redim.label(x='Potential [V]', y='Current [A]') update_sliders(time_stamp) return overlay reactive_baseline = pn.bind(interact_frame, time_step_slider, peak_left_slider, peak_right_slider, limit_left_slider, limit_right_slider) widgets = pn.Column("<br>\n## Baseline set:", peak_left_slider, peak_right_slider, limit_left_slider, limit_right_slider, max_current) occupancy = pn.Row(reactive_baseline, widgets) time_column = pn.Column("<br>\n## Time stamp:", time_step_slider) pn_overlay = pn.Column(time_column, occupancy) interact_frame() return pn_overlay