2

I have created website using Bokeh. My website shows table. I am looking for help on filtering df(Pandas dataframe) based on "Date" criteria. User need to input "from" date and "to" date. and then output table should show up on website.

It seems I need help on creating customJS or any callback function. can someone please help me here?

Need two input boxes to enter "from" date and "to" date and link to table. So that whenever date changes, table should show that particular range dataframe only. Can someone please help me here?

 df.head()
Source = ColumnDataSource(df2.sort_index(ascending=False) )
Columns = [ TableColumn(field=f, title=f, formatter=date, width=75)  for f in date_col]+\
          [ TableColumn(field=f, title=f, formatter=formater,width=75)  for f in ['Benchmark']]+\
          [ TableColumn(field=f, title=f, formatter=formater, width=75)  for f in ['Quality']]+\
          [ TableColumn(field=f, title=f, formatter=formater, width=75)  for f in ['Value']]+\
          [ TableColumn(field=f, title=f, formatter=formater, width=75)  for f in ['Momentum']]+\
          [ TableColumn(field=f, title=f, formatter=formater, width=75)  for f in ['Low_Volatility']]


table1 = DataTable(source = Source, columns = Columns, width = 600, height  = 1000, css_classes = ['my_class'])

select = Select(title="Indices_List:", value="ACWI", options=["ACWI", 
"World", "EM", "EAFE","US", "Canada","Poland"], width= 20)
tab = Panel(child=column(select, table1), title="Universal Table")
tabs = Tabs(tabs=[tab,])

output_notebook()
show(tabs)

Myoutput looks like this

1 Answers1

0

If you are not planning on using a Bokeh Server, you can use text input widgets and javascript callbacks with CustomJS.

https://docs.bokeh.org/en/latest/docs/user_guide/interaction/widgets.html

from bokeh.io import output_file, show
from bokeh.models.widgets import TextInput

    output_file("text_input.html")

    text_input = TextInput(value="default", title="Label:")

    show(text_input)

https://docs.bokeh.org/en/latest/docs/user_guide/interaction/callbacks.html

from bokeh.models.callbacks import CustomJS

   callback = CustomJS(code="""
   // the event that triggered the callback is cb_obj:
   // The event type determines the relevant attributes
   console.log('Tap event occurred at x-position: ' + cb_obj.x)
   """)

   p = figure()
   # execute a callback whenever the plot canvas is tapped
   p.js_on_event('tap', callback)