def test_setting_options_from_list_tuples(self): d = Dropdown() assert d.options == () d.options = [('One', 1), ('Two', 2), ('Three', 3)] assert d.get_state('_options_labels') == {'_options_labels': ('One', 'Two', 'Three')} d.value = 2 assert d.get_state('index') == {'index': 1}
machines.options = machines_options #queues.options = queues_options def on_machine_value_set(_): queues_options = [] exec_sys = machines.value app0 = exec_to_app[exec_sys] for q in range(len(all_apps[app0]["queues"])): queues_options += [all_apps[app0]["queues"][q]["name"]] queues.options = queues_options queues.value = queues_options[0] machines.observe(on_machine_value_set) machines.value = all_apps[app0]["exec_sys"] on_machine_value_set(None) numXSlider = IntSlider(value=0, min=1, max=16, step=1) numYSlider = IntSlider(value=0, min=1, max=16, step=1) numZSlider = IntSlider(value=0, min=1, max=16, step=1) runBtn = Button(description='Run', button_style='primary', layout= Layout(width = '50px')) run_items = [ Box([Label(value="Job Name", layout = Layout(width = '350px')), jobNameText], layout = run_item_layout), Box([Label(value="Machine", layout = Layout(width = '350px')), machines], layout = run_item_layout), Box([Label(value="Queue", layout = Layout(width = '350px')), queues], layout = run_item_layout), Box([Label(value="NX", layout = Layout(width = '350px')), numXSlider], layout = run_item_layout), Box([Label(value="NY", layout=Layout(width = '350px')), numYSlider], layout= run_item_layout), Box([Label(value="NZ", layout=Layout(width = '350px')), numZSlider], layout= run_item_layout),
description=name, disabled=False, indent=False, style={'color': 'blue'}) c.observe(cb_handler, 'value') return c checked_colors = [] cbox_dict = {cat: cmap_checkboxes(cat) for cat in cmap_default} title = HTML('<h1>Color Viewer</h1>') img = Image(width=700, height=600) img.layout.visibility = 'hidden' rows = [] row1 = HBox([title], layout={'justify_content': 'flex-start'}) row2 = HBox([cmap_category, img], layout={'align_items': 'center'}) rows = [row1, row2] layout = VBox(rows) fig = plt.Figure(dpi=144, tight_layout=True, figsize=(6, 3)) ax = fig.add_subplot() remove_ticks_spines(ax) interactive_output(get_checkboxes, {'category': cmap_category}) cmap_category.value = 'qualitative' def ColorViewer(): display(layout)
import matplotlib.font_manager as fm font_list = fm.findSystemFonts(fontpaths=None, fontext='ttf') f = [f.name for f in fm.fontManager.ttflist] print(f) from collections import OrderedDict from IPython.display import (display, clear_output, YouTubeVideo) from ipywidgets import Dropdown dw = Dropdown( options=OrderedDict([('SciPy 2016', 'Ejh0ftSjk6g'), ('PyCon 2016', 'YgtL4S7Hrwo')])) from collections import OrderedDict from IPython.display import (display, clear_output, YouTubeVideo) from ipywidgets import Dropdown dw = Dropdown( options=OrderedDict([('SciPy 2016', 'Ejh0ftSjk6g'), ('PyCon 2016', 'YgtL4S7Hrwo')])) def on_value_change(name, val): clear_output() display(YouTubeVideo(val)) dw.on_trait_change(on_value_change, 'value') dw.value = dw.options['SciPy 2016'] display(dw)
def prototype(self, title=None, start_year=None): """Create a prototype Dashboard""" if title is None: title = "Melbourne CBD Pedestrian Traffic" if start_year is None: start_year = self.years[-1] # inputs year_input = Dropdown(options=self.years, description="Year") month_input = Dropdown(description="Month") sensor_input = SelectMultiple(description="Sensor", layout={"height": "150px"}) def update_inputs(change): """Update available options for month and sensor inputs based on current year""" filtered_data = self.filter(year=year_input.value) # Need to temporarily disable all other custom handlers to prevent input # option changes triggering a UI update. (value changes are ok) month_handlers = month_input._trait_notifiers["value"]["change"] month_input._trait_notifiers["value"]["change"] = [] month_input.options = filtered_data.months month_input._trait_notifiers["value"]["change"] = month_handlers month_input.value = None sensor_handlers = sensor_input._trait_notifiers["value"]["change"] sensor_input._trait_notifiers["value"]["change"] = [] sensor_input.options = filtered_data.sensors sensor_input._trait_notifiers["value"]["change"] = sensor_handlers sensor_input.value = [] year_input.observe(update_inputs, "value") year_input.value = start_year # outputs month_counts_output = interactive_output( self.make_callback("month_counts", height=350, width=550), { "sensor": sensor_input, "year": year_input }, ) sensor_counts_output = interactive_output( self.make_callback("sensor_counts", width=550), { "sensor": sensor_input, "year": year_input, "month": month_input }, ) sensors_map_output = interactive_output( self.make_callback("sensor_map", height=650, width=600), { "sensor": sensor_input, "year": year_input, "month": month_input }, ) sensors_traffic_output = interactive_output( self.make_callback("sensor_traffic", same_yscale=True, width=1200), { "sensor": sensor_input, "year": year_input, "month": month_input }, ) # layout title = HTML(f"<H1>{title}</h1>") inputs = VBox([year_input, month_input, sensor_input]) col1_row1 = HBox( [VBox([HBox([inputs]), month_counts_output]), sensors_map_output]) col1_row2 = sensors_traffic_output col1 = VBox([col1_row1, col1_row2]) col2 = sensor_counts_output rows = [HBox([title]), HBox([col1, col2])] for row in rows: row.layout.justify_content = "center" return VBox(rows)
# In[26]: header = HTML( "<h1>Prediction Model: Mediterrean Sea Weather (Fictional model)</h1>", layout=Layout(height='auto')) header.style.text_align = 'center' basemap_selector = Dropdown(options=list(maps.keys()), layout=Layout(width='auto')) heatmap_selector = Dropdown(options=('Temperature', 'Precipitation'), layout=Layout(width='auto')) # In[27]: basemap_selector.value = 'NASA' m.layout.height = '600px' # In[28]: security_1 = np.cumsum(np.random.randn(150)) + 100. dates = date_range(start='06-20-2020', periods=150) dt_x = bq.DateScale() sc_y = bq.LinearScale() time_series = bq.Lines(x=dates, y=security_1, scales={'x': dt_x, 'y': sc_y}) ax_x = bq.Axis(scale=dt_x) ax_y = bq.Axis(scale=sc_y, orientation='vertical')
def create_dropdown(self, k, anno) -> Dropdown: atype = anno["typing"] wi = Dropdown(description=k, options=anno["options"]) if "default" in anno: wi.value = anno["default"] return wi