3

I am trying to design a front end display for my dataframe.I want to put a button ,selecting which filters my dataframe.I have tried reading documentation and sample examples but till now I haven't succeeded. Here is my code for reference:

source = ColumnDataSource(data=dict())
act=""

def act_good():
    global act
    act='Good'

def update():
    current = data[data['Activity']==act]
    source.data = {
        'Tag'             :current.Tag,
        'UpdateQuality'   : current.UpdateQuality,
        'Activity' : current.Activity
    }


checkbox_act_good = RadioButtonGroup(
        labels=["Activity Good"])
checkbox_act_good.on_click(act_good())


columns = [
    TableColumn(field="Tag", title="Tag"),
    TableColumn(field="UpdateQuality", title="Quality"),
    TableColumn(field="Activity", title="Activity")
]

data_table = DataTable(source=source, columns=columns, width=800)
controls = widgetbox(slider,button,checkbox_group,but)
table = widgetbox(data_table)
curdoc().add_root(row(controls, table))
update()

This is my first time using bokeh.

1 Answer 1

1

You can update in different ways. For example you can create a new ColumnDataSource and update the DataTable source like this:

from bokeh.models import ColumnDataSource
from bokeh.models.widgets.tables import DataTable, TableColumn
from bokeh.models.widgets.buttons import Button
from bokeh.layouts import column
from bokeh.io import curdoc


columns = [
    TableColumn(field="x", title="X"),
    TableColumn(field="y", title="Y"),
]
init_source = ColumnDataSource(data=dict(x=[''],y=['']))
table = DataTable(
    source=init_source,
    columns=columns,
    reorderable=False,
)

def update_table():
    new_source = ColumnDataSource(dict(
        x=[1, 2, 3, 4, 5, 6],
        y=[1, 2, 3, 4, 5, 6],
    ))
    table.source.data = new_source.data

bt = Button(
    label="Update Table",
    button_type="success",
    width=50
)

bt.on_click(update_table)

curdoc().add_root(column(children=[table, bt]))

Launch this file with bokeh serve --show filepath/file.py. You can use a DataFrame as CDS argument like this: ColumnDataSource(df) in order to create the CDS.

Sign up to request clarification or add additional context in comments.

2 Comments

This is very helpful. there is a small typo though - it should read "TableColumn(field="y", title="Y"),"
Thanks, I have corrected it @prk

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.