Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Bokeh - dynamic update widget.Select values
#1
I'm using a Bokeh Select widget, from bokeh.models.widgets import Select which is essentially a dropdown on a web page. eg: http://v4-alpha.getbootstrap.com/components/dropdowns/.  I'm trying to figure out how to update the values after bokeh server has been initialized.  for example.  when the server is started, the Select widget has the values, [foo, bar]. I update that list with an myList.append('baz') so that the list now contains ['foo','bar','baz'] but the widget doesn't show the new value. If the process below seems to complicated, I can create a github project for it.

I worked off of this example: http://demo.bokehplots.com/apps/movies
full source code: https://github.com/bokeh/bokeh/tree/mast...app/movies

1) Use the description.html file from the movies app if you try running the code below. It should be placed in the same dir as the script.
https://github.com/bokeh/bokeh/blob/mast...ption.html

2) you also need to create a dir in the same location as the script.  place at least one file in there.  the name or names of the files in the data dir will appear on the drop down.


from os.path import dirname, join
import os
from bokeh.models import Div, Button
from bokeh.io import curdoc
from bokeh.models.widgets import Select


class myClass:

    def __init__(self):
        '''CONSTRUCTOR'''

        html_path = "description.html"
        FILE_DIR = "./data"
       
        # Initialize the refresh button
        self.refresh_button = Button(label="Refresh")
        self.refresh_button.on_click(self._file_selection_setup)
       
        # Initialize the Selection widget
        self._file_selection_setup()
        self.selection.on_change('value', lambda attr, old, new: self._selection_setup())

        # Data Descriptor -- load base HTML file
        html = open(join(dirname(__file__), html_path)).read()
        self.desc = Div(text=html, width=800)

        # setup widgetbox containing the button and Select dropdown
        self.widgetbox = widgetbox(self.refresh_button, self.file_selection, width=300)


    def _my_selection_setup(self):
        fileList = ps.listdir(FILE_DIR)
        print fileList
        self.file_selection = Select(title="FileInput:", value="selectOne", options=fileList)
        self.widgetbox = widgetbox(self.refresh_button, self.file_selection, width=300)


mc = myClass()
curdoc().add_root(mc.widgetbox)
curdoc().title = "my app"

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Update value selected in option menu when select an item from text box klllmmm 2 1,031 Jun-06-2019, 04:51 AM
Last Post: klllmmm
  Update plot by <Return> bind with entry widget Zorro 1 710 Mar-09-2019, 12:27 PM
Last Post: Zorro
  [Tkinter] update the content of Text widget atlass218 10 6,265 Dec-15-2018, 11:51 AM
Last Post: atlass218
  [Tkinter] Update value in Entry widget dannyH 7 16,116 Apr-02-2017, 10:12 AM
Last Post: dannyH
  Are there Bokeh users on this forum? sixteenornumber 4 2,373 Dec-28-2016, 06:48 PM
Last Post: micseydel

Forum Jump:


Users browsing this thread: 1 Guest(s)