<jupyter_start><jupyter_text>Bokeh server applications let you connect all of the powerful Python libraries for analytics and data science, such as NumPy and Pandas, to rich interactive Bokeh visualizations. Learn about Bokeh's built-in widgets, how to add them to Bokeh documents alongside plots, and how to connect everything to real python code using the Bokeh server.  Understanding Bokeh appsThe main purpose of the Bokeh server is to synchronize python objects with web applications in a browser, so that rich, interactive data applications can be connected to powerful PyData libraries such as NumPy, SciPy, Pandas, and scikit-learn.  Using the current documentLet's get started with building an interactive Bokeh app. This typically begins with importing the curdoc, or "current document", function from bokeh.io. This current document will eventually hold all the plots, controls, and layouts that you create. Your job in this exercise is to use this function to add a single plot to your application.<jupyter_code>from bokeh.io import show
from bokeh.plotting import figure
from ipywidgets import interact
from bokeh.io import push_notebook , output_notebook
# Create a new plot: plot
plot = figure()

# Add a line to the plot
plot.line([1,2,3,4,5], [2,5,4,6,7])

output_notebook()
push_notebook()

show(plot, notebook_handle=True)<jupyter_output><empty_output><jupyter_text>Add a single sliderIn the previous exercise, you added a single plot to the "current document" of your application. In this exercise, you'll practice adding a layout to your current document.Your job here is to create a single slider, use it to create a widgetbox layout, and then add this layout to the current document.The slider you create here cannot be used for much, but in the later exercises, you'll use it to update your plots!<jupyter_code># Perform the necessary imports
from bokeh.io import curdoc
from bokeh.layouts import widgetbox
from bokeh.models import Slider

# Create a slider: slider
slider = Slider(title='my slider', start=0, end=10, step=0.1, value=2)

# Create a widgetbox layout: layout
layout = widgetbox(slider)

# Add the layout to the current document
curdoc().add_root(layout)

show(layout, notebook_handle=True)<jupyter_output><empty_output><jupyter_text>Multiple sliders in one documentHaving added a single slider in a widgetbox layout to your current document, you'll now add multiple sliders into the current document.Your job in this exercise is to create two sliders, add them to a widgetbox layout, and then add the layout into the current document.<jupyter_code># Create first slider: slider1
slider1 = Slider(title='slider1', start=0, end=10, step=0.1, value=2)

# Create second slider: slider2
slider2 = Slider(title='slider2', start=10, end=100, step=1, value=20)
# Add slider1 and slider2 to a widgetbox
layout = widgetbox(slider1, slider2)

# Add the layout to the current document
#curdoc().add_root(layout)

show(layout, notebook_handle=True)
import numpy as np<jupyter_output><empty_output><jupyter_text>How to combine Bokeh models into layoutsLet's begin making a Bokeh application that has a simple slider and plot, that also updates the plot based on the slider.In this exercise, your job is to first explicitly create a ColumnDataSource. You'll then combine a plot and a slider into a single column layout, and add it to the current document.After you are done, notice how in the figure you generate, the slider will not actually update the plot, because a widget callback has not been defined. You'll learn how to update the plot using widget callbacks in the next exercise.All the necessary modules have been imported for you. The plot is available in the workspace as plot, and the slider is available as slider.<jupyter_code>from bokeh.models import ColumnDataSource
x = np.linspace(0, 2*np.pi, 2000)
y = np.sin(x)
p = figure(x_axis_label = 'x', y_axis_label = 'sin(x)')
p.scatter(x, y)
show(p)
from bokeh.layouts import column
# Create ColumnDataSource: source
source = ColumnDataSource(data = {'x':x, 'y':y})
p1 = figure()
# Add a line to the plot
p1.line('x', 'y', source=source)

# Create a column layout: layout
layout = column(widgetbox(slider), p1)

# Add the layout to the current document
#curdoc().add_root(layout)
show(layout, notebook_handle=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06859122401847575, 'fraction_numerical': 0.011316397228637413, 'mean_word_length': 5.552193645990923, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '637142', 'license': 'MIT', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1204, 'n_words': 579, 'path': 'Data Scientist with Python/Course 14 - Interactive Data Visualization with Bokeh/Chapter 3 - Building interactive apps with Bokeh.ipynb', 'repo_name': 'indmitDS/DataCamp-DataScience', 'size': '4330'}