# Live plot with interactivity

**URL:** <https://discourse.bokeh.org/t/live-plot-with-interactivity/10890>\
**Category:** Community Support\
**Created:** [September 25, 2023, 10:32pm UTC](https://discourse.bokeh.org/t/live-plot-with-interactivity/10890 "2023-09-25T22:32:07Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [September 26, 2023, 4:10am UTC](https://discourse.bokeh.org/t/live-plot-with-interactivity/10890/6 "2023-09-26T04:10:02Z")

</div>

Yes, here is an updated version from that example:

```python
class bkapp:  
    df = sea_surface_temperature.copy()

    def __init__ (self):
        self._theme_json = """
           attrs:
                figure:
                    background_fill_color: "#DDDDDD"
                    outline_line_color: white
                    toolbar_location: above
                    height: 500
                    width: 800
                Grid:
                    grid_line_dash: [6, 4]
                    grid_line_color: white
        """

    def callback(self, attr, old, new):
        if new == 0:
            data = self.df
        else:
            data = self.df.rolling('{0}D'.format(new)).mean()
        self.source.data = ColumnDataSource.from_df(data)

    def __call__ (self, doc):
        self.source = ColumnDataSource(data=self.df)
    
        plot = figure(x_axis_type='datetime', y_range=(0, 25),
                      y_axis_label='Temperature (Celsius)',
                      title="Sea Surface Temperature at 43.18, -70.43")
        plot.line('time', 'temperature', source=self.source)
    
        slider = Slider(start=0, end=30, value=0, step=1, title="Smoothing by N Days")
        slider.on_change('value', self.callback)
    
        doc.add_root(column(slider, plot))

```

Then call with

```auto
show(bkapp()) # pass an instance to show

```

I’ll make an issue to add this version to the docs and “officially” support it.

Edit:

> <https://github.com/bokeh/bokeh/issues/13395>
>
> ref: https://discourse.bokeh.org/t/live-plot-with-interactivity/10890/6?u=bryan
> …
> 
> While answering the above user question, it occurred to me that callable objects might be a much simpler/more straightforward way to express apps in notebooks that does not involve nested functions (and even potentially having to resort to \`nonlocal\` as in that question). 
> 
> The existing code want's to "tighten up" the types for \`show\`:
> 
> https://github.com/bokeh/bokeh/blob/bb1582ab7be57ac53baed5edae9ab28db4fe9495/src/bokeh/io/showing.py#L148
> 
> But I now think we should \*not\* do that, and explicitly support (test) with callable objects like the code in the referenced disussion, and even update the example to use this method.

---

_[View the full topic](https://discourse.bokeh.org/t/live-plot-with-interactivity/10890)._
