2

我使用 Bokeh 创建了网站。我的网站显示表格。我正在寻求有关根据“日期”标准过滤 df(Pandas 数据框) 的帮助。用户需要输入“开始”日期和“结束”日期。然后输出表应该显示在网站上。

看来我需要帮助来创建 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)

我的输出看起来像这样

4

1 回答 1

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)
于 2019-12-28T14:17:16.997 回答