基于日期的散景表过滤器

时间:2019-07-31 14:19:30

标签: python bokeh pandas-bokeh

我已经使用Bokeh创建了网站。我的网站显示表格。我正在寻找有关基于“日期”条件过滤df(熊猫数据框)的帮助。用户需要输入“开始”日期和“结束”日期。然后输出表应显示在网站上。

似乎我在创建customJS或任何回调函数方面需要帮助。有人可以帮我吗?

需要两个输入框输入“起始”日期和“终止”日期并链接到表格。因此,只要日期更改,表格就应仅显示特定范围的数据框。 有人可以帮我吗?

 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 个答案:

答案 0 :(得分:0)

如果您不打算使用Bokeh Server,则可以在CustomJS中使用文本输入小部件和javascript回调。

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)
相关问题