0

New in Bokeh, I'm trying to build a html page with boxgroupcheck.

Below is df

UC_Month dep_delayed_15min_count dep_delayed_15min_sum dep_delayed_15min_Percent UC
AA-01     797                         153                0.192                   AA
AA-02     708                         128                0.181                   AA
AA-03     799                         157                0.196                   AA

I create a plot with bokeh using the following code

# Call once to configure Bokeh to display plots inline in the notebook.
output_notebook()

def plot_col(data, col, long, larg):

    # Output file
    output_file("bar_stacked_split.html")

    # Define Labels
    group = data[col].unique()
    target = ['Flight on Time', 'Flight Delayed']
    colors = ['blue', 'red']

    # Define Values
    val = {'Group': group,
             'Flight on Time' : 1 - data['dep_delayed_15min_Percent'], 
             'Flight Delayed' : data['dep_delayed_15min_Percent']}

    # Define plots
    p1 = figure(plot_width = long, plot_height = larg, y_range = group, 
                tools=["box_zoom", "wheel_zoom", "lasso_select", "reset", "save"], tooltips= "$name @Group: @$name")

    p1.hbar_stack(target, y= 'Group', height=0.9, color=colors, source= val, legend_label= target)


    val2 = {'Group': group,
             'Flight on Time'   : data['dep_delayed_15min_count'] - data['dep_delayed_15min_sum'], 
             'Flight Delayed'   : data['dep_delayed_15min_sum'] }

    p2 = figure(plot_width= long, plot_height= larg, y_range= group, 
                  tools=["box_zoom", "wheel_zoom", "lasso_select", "reset", "save"], tooltips= "$name @Group: @$name")

    p2.hbar_stack(target, y='Group', height=0.9, color=colors, source= val2, legend_label= target)


    return show(row(p1, p2))

Then I apply the plot function

plot_col(train_ucmonth, 'UC_Month', 750, 5550)

Which gives me this output

enter image description here

So, what I'm trying to do after that is to create a checkbox with train_ucmonth.UC.unique() and update the html output

I have found many ressources on internet regarding the checkboxgroup such as this one

However, my problem is that I already have a 'target' that I have 'flight delayed' and 'flight not delayed'.

Thus, my question is how can I add a filter box with column 'UC' and keeping my target like in my plot.

Edit

How can I add in the above plot a checkbox with the following values?

  • WN
  • AA
  • UA
  • OO
  • OA

By selecting only one unique carrier, the plot should be updated.

Thanks for anyone helping!

A2N15
  • 595
  • 4
  • 20
  • It is not clear what you want. Please clarify / rephrase your question. – Tony Jun 11 '20 at 23:24
  • @Tony Thanks for your feedbacks, please find my updated question – A2N15 Jun 12 '20 at 06:26
  • You could use Bokeh `CheckboxGroup` for this in combination with `JavaScript` or `Python` callback. [This page](https://docs.bokeh.org/en/latest/docs/user_guide/jupyter.html) describes how to use Bokeh server for `Python` callbacks. And [here](https://stackoverflow.com/questions/40533394/updating-bokeh-plot-with-a-bokeh-widget-in-jupyter-notebook) is en example of using Bokeh widgets in `JavaScript` (`CustomJS`) callback in Jupyter Notebook. Alternative to Bokeh widgets is to use the `ipywidgets` and `ipywidgets.interact`. – Tony Jun 12 '20 at 11:12

0 Answers0