def main(): buttons1 = [pn.widgets.Button(name=f"{i}") for i in range( 0, 5, )] example1 = pn.WidgetBox( *buttons1, background="blue", sizing_mode="stretch_width", name="Example 1", ) buttons2 = [ pn.widgets.Button( name=f"{i}", max_width=50, ) for i in range( 0, 5, ) ] example2 = pn.WidgetBox( *buttons2, background="green", width=100, name="Example 2", ) app = pn.Column( example1, example2, sizing_mode="stretch_width", ) app.servable()
def __init__(self, data): super().__init__() self.data = data dim_header = pn.pane.Markdown('### Plot Dimensions', margin=(0, 20, 0, 20)) self.x = pn.widgets.Select(name='x', width=240, margin=(0, 20, 5, 20)) self.y = pn.widgets.Select(name='y', width=240, margin=(0, 20, 20, 20)) agg_header = pn.pane.Markdown('### Aggregations', margin=(0, 20, 0, 20)) self.agg_selectors = pn.Column() self.agg_opts = [ 'select', 'animate', 'mean', 'max', 'min', 'median', 'std', 'count' ] self.series_col = pn.Column() self.are_var_coords = False self._register(self.x, 'x') self._register(self.y, 'y') self.connect('x', self.change_y) self.connect('y', self.change_dim_selectors) self.panel = pn.Column(pn.Row( pn.WidgetBox(dim_header, self.x, self.y, background=(240, 240, 240)), pn.Spacer(), pn.WidgetBox(agg_header, self.agg_selectors, background=(240, 240, 240))), self.series_col, name='Axes')
def _setup_ui(self) -> None: self._sidebar.append(pn.Accordion(("Input Files", pn.WidgetBox(self.dataset_file)), active=[0])) if self._display_variables: self._sidebar.append( pn.Accordion( ( "Variables", pn.WidgetBox( self.longitude_var, self.latitude_var, self.elevation_var, self.simplices_var, self.time_var, ), ) ) ) self._sidebar.append( pn.Accordion( ("Display Options", pn.WidgetBox(self.timestamp, self.relative_colorbox, self.show_grid)), active=[0], ), ) if self._display_stations: self._sidebar.append( pn.Accordion(("Stations", pn.WidgetBox(self.stations_file, self.stations))), ) self._sidebar.append(self.render_button)
def draw_date_vars(df,dep,datevars, num_vars, chart_format, modeltype='Regression',verbose=0): #### Now you want to display 2 variables at a time to see how they change over time ### Don't change the number of cols since you will have to change rows formula as well df = df[:] imgdata_list = list() image_count = 0 N = len(num_vars) dft = df.set_index(pd.to_datetime(df.pop(datevars[0]))) if N < 2: var1 = num_vars[0] width_size = 5 height_size = 5 fig = plt.figure(figsize=(width_size,height_size)) dft[var1].plot(title=var1, label=var1) fig.suptitle('Time Series Plot of %s' %var1, fontsize=20,y=1.08) if verbose == 2: imgdata_list.append(save_image_data(fig, image_count, chart_format)) image_count += 1 return imgdata_list if isinstance(dft.index, pd.DatetimeIndex) : dft = dft[:] pass else: dft = dft[:] try: col = datevars[0] if dft[col].map(lambda x: 0 if len(str(x)) == 4 else 1).sum() == 0: if dft[col].min() > 1900 or dft[col].max() < 2100: dft[col] = dft[col].map(lambda x: '01-01-'+str(x) if len(str(x)) == 4 else x) dft.index = pd.to_datetime(dft.pop(col), infer_datetime_format=True) else: print('%s could not be indexed. Could not draw date_vars.' %col) return imgdata_list else: dft.index = pd.to_datetime(dft.pop(col), infer_datetime_format=True) except: print('%s could not be indexed. Could not draw date_vars.' %col) return imgdata_list ####### Draw the time series for Regression and DepVar if modeltype == 'Regression' or dep == None or dep == '': kind = 'line' plot = dft[num_vars+[dep]].hvplot( height=400, width=600,kind=kind, title='Time Series Plot of all Numeric variables and Target').opts(legend_position='top_left') hv_panel = pn.Row(pn.WidgetBox( kind), plot) if verbose == 2: imgdata_list = append_panels(hv_panel, imgdata_list, chart_format) image_count += 1 else: ######## This is for Classification problems only kind = 'line' plot = dft[num_vars+[dep]].hvplot(groupby=dep, height=400, width=600,kind=kind, title='Time Series Plot of all Numeric variables by Target').opts(legend_position='top_left') hv_panel = pn.Row(pn.WidgetBox( kind), plot) if verbose == 2: imgdata_list = append_panels(hv_panel, imgdata_list, chart_format) image_count += 1 return hv_panel
def panel(self): from_box = pn.WidgetBox( pn.Column(self._from_location, pn.Column(self.file_manager.cross_selector))) to_box = pn.WidgetBox(pn.Column(self.param.to_location, self.param.to_directory), width=900, width_policy='max') return pn.Column(from_box, to_box, pn.Param(self.param.transfer_button))
def widget_cross_sections(self): self._widget_select_cross_section = pn.widgets.RadioBoxGroup(name='Available Cross sections', options=list(self.section_dict.keys()), inline=False ) self._widget_select_cross_section.param.watch(self._callback_selection_plot2d, 'value', onlychanged=False) self._widget_update_cross_section = pn.widgets.Button(name="Update Cross Section", button_type="success") self._widget_update_cross_section.param.watch(self._callback_cross_section, 'clicks', onlychanged=False) self._w_section_name = pn.widgets.TextInput(name="Name cross section:", value='CS_1') self._w_p1_x = pn.widgets.TextInput(name='x:', value= '10.0', width=60) self._w_p1_y = pn.widgets.TextInput(name='y:', value= '20.0', width=60) self._w_p2_x = pn.widgets.TextInput(name='x:', value='200.0', width=60) self._w_p2_y = pn.widgets.TextInput(name='y:', value='400.0', width=60) self._widget_add_cs = pn.widgets.Button(name="Add cross section", button_type="success") self._widget_add_cs .param.watch(self._callback_add_cs, 'clicks', onlychanged=False) self._w_remove_name = pn.widgets.AutocompleteInput(name='Cross section name', options=list(self.section_dict.keys())) self._widget_remove_cs = pn.widgets.Button(name="Remove cross section", button_type="success") self._widget_remove_cs.param.watch(self._callback_remove_cs, 'clicks', onlychanged=False) widgets = pn.Column('### Creation of 2D Plots', self._widget_update_cross_section, '<b>add new cross section</b>', pn.WidgetBox(self._w_section_name, pn.Row(pn.WidgetBox('From', self._w_p1_x, self._w_p1_y, horizontal=True), pn.WidgetBox('To', self._w_p2_x, self._w_p2_y, horizontal=True))), self._widget_add_cs, '<b>Remove cross section</b>', self._w_remove_name, self._widget_remove_cs, '<b>Select cross section to display</b>', self._widget_select_cross_section, ) panel = pn.Row(widgets, self.panel_plot_2d) return panel
def show_widgets(self): widget = pn.Column(self._widget_activate_gradient_descend, self._widget_optimum, self._widget_speed_gradient_descend, "<b>Frame controller</b>", self._widget_activate_frame_capture, self._widget_refresh_frame) column = pn.Column( "#Simulation options", self._widget_selector, self._widget_search_active, "<b>Controllers</b>", self._widget_sleep, self._widget_margins_crop, "<b>Visualization options</b>", self._widget_plot_points, self._widget_plot_contour, "<b>Modify constants</b> ", self._widget_variance, self._widget_number_samples, "<b>Adaptive options</b>", self._widget_memory_steps, "<b> Hamiltonian options", self._widget_leapfrog_step, self._widget_leapfrog_points) histogram = pn.WidgetBox(self._widget_histogram_refresh, self.histogram) row = pn.Row(column, widget) tabs = pn.Tabs( ('Controllers', row), ("Histogram plot", histogram), ) return tabs
def widgets_load_simulation(self): self._widget_simulation_folder = pn.widgets.TextInput(name='Specify the folder path to load the simulation:') self._widget_simulation_folder.value = self.simulation_folder self._widget_available_release_areas = pn.widgets.RadioBoxGroup(name='Available release areas', options=self.release_id_all, inline=False, value=None) self._widget_load = pn.widgets.Button(name='Refresh list', button_type='warning') self._widget_load_release_area = pn.widgets.Button(name='Load selected release area', button_type="success") self._widget_simulation_folder.param.watch(self._callback_filename, 'value', onlychanged=False) self._widget_available_release_areas.param.watch(self._callback_available_release_areas, 'value', onlychanged=False) self._widget_load.param.watch(self._callback_load_files_folder, 'clicks', onlychanged=False) self._widget_load_release_area.param.watch(self._callback_load_release_area, 'clicks', onlychanged=False) col1 = pn.Column("## Load widget", '<b>File path</b>', self._widget_simulation_folder, '<b> Load possible release areas</b>', self._widget_load) col2 = pn.Column('<b>Load Simulation</b>', self._widget_load_release_area, '<b>Select a release area</b>', pn.WidgetBox(self._widget_available_release_areas)) panel = pn.Row(col1, col2) return panel
def calibrate_sensor(self): widgets = pn.WidgetBox( '<b>Load a projector calibration file</b>', self._widget_json_filename_load_projector, self._widget_json_load_projector, '<b>Distance from edges (pixel)</b>', self._widget_s_top, self._widget_s_right, self._widget_s_bottom, self._widget_s_left, #self._widget_s_enable_auto_cropping, #self._widget_s_automatic_cropping, pn.layout.VSpacer(height=5), '<b>Distance from sensor (mm)</b>', self._widget_s_min, self._widget_s_max, self._widget_refresh_frame) box = pn.Column( '<b>Physical dimensions of the sandbox</b>', self._widget_box_width, self._widget_box_height, ) save = pn.Column('<b>Save file</b>', self._widget_json_filename, self._widget_json_save) rows = pn.Row(widgets, self.calib_notebook_frame) panel = pn.Column('## Sensor calibration', rows) tabs = pn.Tabs(('Calibration', panel), ("Box dimensions", box), ("Save files", save)) return tabs
def __init__(self, data): super().__init__() self.data = data self.displayer = Display(self.data) self.describer = Describe(self.data) self.fields = Fields(self.data) self.style = Style() self.coord_setter = CoordSetter(self.data) self.tabs = pn.Tabs( pn.Row(self.displayer.panel, self.describer.panel, name='Variables', width_policy='max'), self.coord_setter.panel, self.fields.panel, self.style.panel, background='#f5f5f5', width_policy='max', margin=20 ) if has_cartopy: from .projection import Projection self.projection = Projection() self.tabs.append(self.projection.panel) self.fields.connect('x', self.check_is_projectable) self.fields.connect('y', self.check_is_projectable) self.displayer.connect("variable_selected", self.describer.setup) self.displayer.connect("variable_selected", self.fields.setup) self.displayer.connect("variable_selected", self.style.setup) self.panel = pn.WidgetBox(self.tabs, width_policy='max')
def _chart_app(chart): return pn.Row( pn.WidgetBox( pn.Param( chart, parameters=[ "height", "width", "sizing_mode", "margin", "object", "object_update", "event", ], widgets={ "object": pn.widgets.LiteralInput, "object_update": pn.widgets.LiteralInput, "event": pn.widgets.StaticText, }, ), sizing_mode="fixed", ), chart, sizing_mode="stretch_both", )
class KernelsController: channels: List[streams.Pipe] widget_box: pn.WidgetBox = pn.WidgetBox() selector_widget_kernel: pn.widgets.Widget = pn.widgets.Select() widget_kernel_instances: List[Kernel] = field(init=False, default=None) widget_kernel_classes: List[Type] = field( default_factory=lambda: [SquaredExponential, Matern52, Matern32, Matern12, ArcCosine, Linear]) def __post_init__(self): self.widget_kernel_instances = [ cls(self.channels) for cls in self.widget_kernel_classes ] first_instance = self.widget_kernel_instances[0] self.selector_widget_kernel.options = self.widget_kernel_instances self.selector_widget_kernel.value = first_instance def update_parameter_box(event): kernel_widget = first_instance if event.new is None else event.new self.widget_box.objects = kernel_widget.widgets for channel in self.channels: channel.send(kernel_widget.tf_kernel) self.selector_widget_kernel.param.watch(update_parameter_box, "value") self.selector_widget_kernel.param.trigger("value") def view(self): return pn.Column(self.selector_widget_kernel, self.widget_box)
def test_get_advanced_app(): src = "#JSGF V1.0; grammar colors; public <color> = aqua | azure | beige | bisque | black | blue | brown | chocolate | coral | crimson | cyan | fuchsia | ghostwhite | gold | goldenrod | gray | green | indigo | ivory | khaki | lavender | lime | linen | magenta | maroon | moccasin | navy | olive | orange | orchid | peru | pink | plum | purple | red | salmon | sienna | silver | snow | tan | teal | thistle | tomato | turquoise | violet | white | yellow ;" # noqa speech_to_text = SpeechToText(button_type="success", continuous=True) grammar_list = GrammarList() grammar_list.add_from_string(src, 1) speech_to_text.grammars = grammar_list results_as_html_panel = pn.pane.Markdown(margin=(0, 15, 0, 15)) @pn.depends(speech_to_text, watch=True) def update_results_html_panel(results): results_as_html_panel.object = speech_to_text.results_as_html speech_to_text_settings = pn.WidgetBox( pn.Param( speech_to_text, parameters=[ "start", "stop", "abort", "grammars", "lang", "continuous", "interim_results", "max_alternatives", "service_uri", "started", "results", "value", "started", "audio_started", "sound_started", "speech_started", "button_type", "button_hide", "button_started", "button_not_started", ], ), ) app = pn.Column( pn.pane.HTML( "<h1>Speech to Text <img style='float:right;height:40px;width:164px;margin-right:40px' src='https://panel.holoviz.org/_static/logo_horizontal.png'></h1>", # noqa background="black", style={"color": "white", "margin-left": "20px"}, margin=(0, 0, 15, 0), ), speech_to_text, pn.Row( pn.Column(pn.pane.Markdown("## Settings"), speech_to_text_settings), pn.layout.VSpacer(width=25), pn.Column( pn.pane.Markdown("## Results"), results_as_html_panel, ), ), width=800, sizing_mode="fixed", ) return app
def get_province_select_widget(province_list): province_group = pn.widgets.CrossSelector( name='Province', value=[], options=province_list, ) return pn.WidgetBox('## Select Provinces', province_group)
def panel(self): return pn.Column( self.file_select.panel, pn.WidgetBox( pn.Param( self, parameters=['cmd', 'n', 'update_btn'], widgets={ 'cmd': { 'width': 100 }, 'n': pn.widgets.Spinner(value=self.n, width=100, name=self.param.n.label), 'update_btn': { 'button_type': 'primary', 'width': 100, 'align': 'end' } }, default_layout=pn.Row, show_name=False, ), width=400, ), self.view, width_policy='max', height_policy='max', max_height=1000, )
def get_tmpl(): tmpl = pn.template.VanillaTemplate(title='Icon Menu') dd0 = DragMenu(pn.WidgetBox(pn.pane.Markdown('# H1aaaa'), pn.widgets.FloatSlider(value=2,end=10))) dd1 = DragMenu(pn.WidgetBox(pn.pane.Markdown('# H2aaaa'), pn.widgets.FloatSlider(value=2,end=10), pn.pane.PNG('https://holoviz.org/assets/earthquakes.png', width= 500, height=300) ), icon='bicycle') grid = pn.GridBox('', 'light', 'dark', ncols=3) for color in pn.indicators.LoadingSpinner.param.color.objects: dark = pn.indicators.LoadingSpinner(width=50, height=50, value=True, color=color, bgcolor='dark') light = pn.indicators.LoadingSpinner(width=50, height=50, value=True, color=color, bgcolor='light') grid.extend((color, light, dark)) xs = np.linspace(0, np.pi) freq = pn.widgets.FloatSlider(name="Frequency", start=0, end=10, value=2) phase = pn.widgets.FloatSlider(name="Phase", start=0, end=np.pi) @pn.depends(freq=freq, phase=phase) def sine(freq, phase): return hv.Curve((xs, np.sin(xs*freq+phase))).opts( responsive=True, min_height=500) @pn.depends(freq=freq, phase=phase) def cosine(freq, phase): return hv.Curve((xs, np.cos(xs*freq+phase))).opts( responsive=True, min_height=500) dd2 = DragMenu(pn.WidgetBox(grid)) dd3 = DragMenu(pn.WidgetBox('# Trig control', freq, phase)) row = pn.Row(pn.Spacer(sizing_mode='stretch_width'), dd0, dd1, dd2, dd3, margin=(0,0,0,0), sizing_mode='stretch_width') tmpl.header.append(row) tmpl.main.append(pn.Row(cosine,sizing_mode='stretch_both')) return tmpl
def options_page(self): return pn.WidgetBox(self.search_pattern_input, self.tokenize_button, height = 300, width = 300 )
def options_page(self): return pn.WidgetBox(self.stem_button, self.lem_button, height = 300, width = 300 )
def options_page(self, help_text): return pn.WidgetBox(help_text, self.tt_model, self.test_slider, self.tt_button, height=375, width=300)
def options_page(self): return pn.WidgetBox(self.we_model, self.we_button, height = 300, width = 300 )
def _export_widgets(self): export_button = pn.widgets.Button(name='export') export_button.on_click(self._export_callback) return pn.WidgetBox( pn.Param(self.param.export_fun, widgets={'export_fun': { 'name': '' }}), export_button)
def panel(self): """The image viewer as a panel to display. """ self._set_css() # Widget to show image informations. info_widget = self._get_image_info info_container = pn.Column(pn.pane.Markdown("## Informations"), info_widget) # Widget with parameter widgets to control image viewer. parameters_widget = pn.Param( self.param, show_name=False, parameters=self.active_param_widgets, widgets=self.param_widgets, sizing_mode="scale_both", ) parameters_widget = pn.WidgetBox(parameters_widget) parameters_container = pn.Column( pn.pane.Markdown("## Viewer Configurations"), parameters_widget ) # Assemble informations and parameters widgets. tools_widget = pn.Column(info_container, parameters_container) # Image container image_container = pn.Row(self._get_fig) # Log container log_container = self.log.panel(height=200) # Viewer layout main_pane_args = {} main_pane_args["css_classes"] = [f"viewer-{self.viewer_id}"] main_pane_args["margin"] = 0 if self.width and self.height: main_pane_args["width"] = self.width main_pane_args["height"] = self.height elif self.width: main_pane_args["width"] = self.width main_pane_args["sizing_mode"] = "stretch_height" elif self.height: main_pane_args["height"] = self.height main_pane_args["sizing_mode"] = "stretch_width" else: main_pane_args["sizing_mode"] = "scale_both" gspec = pn.GridSpec(**main_pane_args) gspec[0, :1] = tools_widget gspec[0, 1:20] = image_container # gspec[1, :20] = viewer.drawer.panel() gspec[1, :20] = log_container return gspec
def widget(self): scatter_wg = pn.WidgetBox( 'Scatter', self.param.x_key, self.param.y_key, self.param.color_key, ) return pn.Row(scatter_wg, self.io_widgets)
def widget_box(self): return pn.WidgetBox( pn.Param( self.param, widgets={ 'year': pn.widgets.RadioButtonGroup, 'metric': pn.widgets.RadioBoxGroup, } ), )
def draw_pair_scatters(dfin,nums,problem_type,chart_format, dep=None, classes=None, lowess=False,verbose=0): """ #### PAIR SCATTER PLOTS ARE NEEDED ONLY FOR CLASSIFICATION PROBLEMS IN NUMERIC VARIABLES ### This is where you plot a pair-wise scatter plot of Independent Variables against each other#### """ dft = dfin[:] image_count = 0 imgdata_list = list() if len(nums) <= 1: return classes = copy.deepcopy(classes) height_size = 400 width_size = 600 if problem_type == 'Regression' or problem_type == 'Clustering': ########## This is for Regression problems ########## ######### Here we plot a pair-wise scatter plot of Independent Variables #### colors = cycle('brycgkbyrcmgkbyrcmgkbyrcmgkbyr') ### Only 1 color is needed since only 2 vars are plotted against each other ## x = pn.widgets.Select(name='x', options=nums) y = pn.widgets.Select(name='y', options=nums) kind = 'scatter' plot = dft.hvplot(x=x, y=y, kind=kind, height=height_size, width=width_size, color=next(colors), title='Pair-wise Scatter Plot of two Independent Numeric variables') hv_panel = pn.Row(pn.WidgetBox(x, y),plot) if verbose == 2: imgdata_list = append_panels(hv_panel, imgdata_list, chart_format) image_count += 1 else: ########## This is for Classification problems ########## ######### Here we plot a pair-wise scatter plot of Independent Variables #### target_vars = dft[dep].unique() x = pn.widgets.Select(name='x', options=nums) y = pn.widgets.Select(name='y', options=nums) kind = 'scatter' plot = dft.hvplot(x=x, y=y, kind=kind, by=dep, height=height_size, width=width_size, title='Pair-wise Scatter Plot of two Independent Numeric variables') hv_panel = pn.Row(pn.WidgetBox(x, y), plot) if verbose == 2: imgdata_list = append_panels(hv_panel, imgdata_list, chart_format) image_count += 1 ####### End of Pair Scatter Plots ###### return hv_panel
def widgets_aruco(self): self._create_aruco_widgets() widgets = pn.WidgetBox(self._widget_aruco_scatter, self._widget_aruco_annotate, self._widget_aruco_connect, self._widget_aruco_color) panel = pn.Column("<b> Dashboard for aruco Visualization </b>", widgets) return panel
def widget_boreholes(self): self._widget_show_boreholes = pn.widgets.Button( name="Show Boreholes panel", button_type="success") self._widget_show_boreholes.param.watch(self._callback_show_boreholes, 'clicks', onlychanged=False) self._widget_show_boreholes_pyvista = pn.widgets.Button( name="Show Boreholes pyvista", button_type="warning") self._widget_show_boreholes_pyvista.param.watch( self._callback_show_boreholes_pyvista, 'clicks', onlychanged=False) self._w_borehole_name = pn.widgets.TextInput(name='Borehole name', value='BH_1') self._w_x = pn.widgets.TextInput(name='x:', value='10.0', width=60) self._w_y = pn.widgets.TextInput(name='y:', value='20.0', width=60) self._widget_add_bh = pn.widgets.Button(name="Add borehole", button_type="success") self._widget_add_bh.param.watch(self._callback_add_bh, 'clicks', onlychanged=False) self._w_remove_borehole_name = pn.widgets.AutocompleteInput( name='Remove borehole name', options=list(self.borehole_dict.keys())) self._widget_remove_bh = pn.widgets.Button(name="Remove borehole", button_type="success") self._widget_remove_bh.param.watch(self._callback_remove_bh, 'clicks', onlychanged=False) self._widget_boreholes_available = pn.widgets.RadioBoxGroup( name='Available boreholes', options=list(self.borehole_dict.keys()), inline=False, disabled=True) widgets = pn.Column( '### Creation of boreholes', self._widget_show_boreholes, self._widget_show_boreholes_pyvista, '<b>add new borehole </b>', pn.WidgetBox(self._w_borehole_name, pn.Row(self._w_x, self._w_y)), self._widget_add_bh, '<b>Remove borehole</b>', self._w_remove_borehole_name, self._widget_remove_bh, '<b>Loaded boreholes</b>', self._widget_boreholes_available, ) # TODO: add method to include more boreholes return widgets
def _create_view(self): self.settings_panel = pn.Param( self, parameters=["value_a", "value_b", "value_c"]) self.plot_panel = pn.pane.HoloViews(sizing_mode="stretch_width") self.progress = pn.widgets.Progress(sizing_mode="stretch_width", bar_color="primary") self.view = pn.Column( self.progress, pn.Row(pn.WidgetBox(self.settings_panel), self.plot_panel, sizing_mode="stretch_width"), )
def widgets_aruco(self): self._create_aruco_widgets() if self.Aruco.kinect == "dummy": pane = self._create_dummy_aruco() else: pane = None widgets = pn.WidgetBox(self._widget_aruco_scatter, self._widget_aruco_annotate, self._widget_aruco_connect, self._widget_aruco_color) panel = pn.Column("<b> Dashboard for aruco Visualization </b>", pn.Row(widgets, pane)) return panel
def df_pane(self): if self.results == False: self.result_pane = self.display_df else: self.result_pane = pn.pane.Markdown(f""" {self.result_string} """, width=500, height=350) return pn.WidgetBox(self.result_pane, height=375, width=450)