Best practices for displaying notebook visualizations in dashboards

As a notebook author, you can use some coding best practices to ensure that notebook visualizations are properly displayed when they are rendered in dashboards.

Resizing a Bokeh visualization

For the dashboard to properly resize any Bokeh visualization, don't hardcode the visualization width and height elements in the notebook. Also, when creating any figure, plot, or column, use the parameter sizing_mode='scale_width'.

Here is an example of the correct coding practice:

```
from bokeh.plotting import figure, show

x = [1, 2, 3]
y = [1, 2, 3]

p = figure(sizing_mode='scale_width')
p.line(x, y)

show(p)
```

The visualizations that are coded this way scale properly in the dashboard, maintaining their aspect ratio.

Reloading a Bokeh visualization after a browser refresh

For a dashboard to properly reload a Bokeh visualization after a browser refresh, include the Bokeh initialization statement output_notebook() in the applicable notebook output cells.

Here is an example of the correct coding practice:


```
#  Notebook cell 1
from bokeh.plotting import figure, show

x = [1, 2, 3]
y = [1, 2, 3]

p = figure(sizing_mode='scale_width')
p.line(x, y)

# Notebook cell 2
output_notebook()
show(p)
```