### Start Headless Chrome for Examples Tests Source: https://docs.bokeh.org/en/latest/docs/dev_guide/testing.html Before running example tests locally, start a customized headless Chrome browser from the bokehjs directory. This is a prerequisite for the examples testing framework. ```bash cd bokehjs node make test:run:headless ``` -------------------------------- ### Run Bokeh Server Example (Linux/macOS) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/setup.html Start the Bokeh server with an example application on Linux or macOS. Set BOKEH_DEV=false to run in production mode. ```bash BOKEH_DEV=false python -m bokeh serve --show examples/server/app/sliders.py ``` -------------------------------- ### Run Bokeh Server Example (Windows CMD) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/setup.html Start the Bokeh server with an example application on Windows using the Command Prompt. Set BOKEH_DEV=false to run in production mode. ```cmd set BOKEH_DEV=false python -m bokeh serve --show examples\server\app\sliders.py ``` -------------------------------- ### Run Bokeh Server Example (Windows PowerShell) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/setup.html Start the Bokeh server with an example application on Windows using PowerShell. Set BOKEH_DEV=false to run in production mode. ```powershell $Env:BOKEH_DEV = "False" python.exe -m bokeh serve --show .\examples\server\app\sliders.py ``` -------------------------------- ### Run Bokeh Examples Tests with Pytest Source: https://docs.bokeh.org/en/latest/docs/dev_guide/testing.html After starting the headless Chrome tool, execute the examples tests from the top-level source directory using pytest. This command initiates the test suite and generates a report. ```bash pytest tests/test_examples.py ``` -------------------------------- ### Start Bokeh Server Source: https://docs.bokeh.org/en/latest/docs/first_steps/first_steps_9.html Use this command to start Bokeh in server mode from the command line. ```bash bokeh serve ``` -------------------------------- ### Start BokehJS Devtools Server Source: https://docs.bokeh.org/en/latest/docs/dev_guide/debug_headless_chrome.html Use this command to start a BokehJS devtools server for debugging. ```bash node test/devtools server ``` -------------------------------- ### Serve Documentation Locally (Linux/macOS) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/documentation.html Starts a web server to display the built documentation and opens it in a web browser. This is necessary for documentation that relies on JavaScript. ```bash make serve ``` -------------------------------- ### Serve Documentation Locally (Windows CMD) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/documentation.html Starts a web server to display the built documentation and opens it in a web browser using the make.bat script in the Command Prompt. ```batch make.bat serve ``` -------------------------------- ### Test Bokeh installation and environment Source: https://docs.bokeh.org/en/latest/docs/dev_guide/setup.html Run this command to verify that Bokeh is installed correctly and that your environment is properly configured. It displays detailed information about your Bokeh setup. ```python python -m bokeh info ``` -------------------------------- ### Serve Documentation Locally (Windows PowerShell) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/documentation.html Starts a web server to display the built documentation and opens it in a web browser using the make.bat script in PowerShell. ```powershell .\make.bat serve ``` -------------------------------- ### Set up Data, Figure, and Renderer Source: https://docs.bokeh.org/en/latest/docs/first_steps/first_steps_9.html Prepare sample data and create a Bokeh figure with scatter plot points. ```python x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y = [4, 5, 5, 7, 2, 6, 4, 9, 1, 3] p = figure(x_range=(1,9), width=500, height=250) points = p.scatter(x=x, y=y, size=30, fill_color="#21a7df") ``` -------------------------------- ### Setting Model Properties Individually Source: https://docs.bokeh.org/en/latest/docs/reference/models/plots.html Example of initializing a `Range1d` model and setting its `start` and `end` properties individually. ```python from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 ``` -------------------------------- ### Run Standalone Example (Windows CMD) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/setup.html Execute a standalone Bokeh example on Windows using the Command Prompt. Ensure the BOKEH_RESOURCES environment variable is set to 'inline' or 'absolute-dev'. ```cmd set BOKEH_RESOURCES=inline python examples\basic\data\transform_markers.py ``` -------------------------------- ### Complete Scale Bar Example with Custom Units Source: https://docs.bokeh.org/en/latest/docs/user_guide/basic/annotations.html A full example demonstrating a plot with a vertical scale bar configured for custom metric units (MeV based on eV). Includes data generation, plot setup, and layout. ```python import numpy as np from bokeh.layouts import column from bokeh.models import ColumnDataSource, Metric, RangeTool, ScaleBar from bokeh.plotting import figure, show n_points = 3000 x_values = np.linspace(0, 100, n_points) y_values = np.random.randn(n_points).cumsum() source = ColumnDataSource(data=dict(x=x_values, y=y_values)) detailed_plot = figure( width=800, height=300, tools=["xpan", "xzoom_in", "xzoom_out", "reset", "wheel_zoom"], toolbar_location="above", active_scroll="wheel_zoom", background_fill_color="#efefef", x_range=(22, 30), y_axis_location=None, ) detailed_plot.line("x", "y", source=source) scale_bar = ScaleBar( range=detailed_plot.y_range, unit="MeV", dimensional=Metric(base_unit="eV"), orientation="vertical", location="top_left", background_fill_color=None, border_line_color=None, ) detail_plot.add_layout(scale_bar) select_plot = figure( width=detailed_plot.width, height=150, y_range=detailed_plot.y_range, y_axis_location=None, tools="", toolbar_location=None, background_fill_color=detailed_plot.background_fill_color, ) select_plot.line("x", "y", source=source) select_plot.x_range.range_padding = 0 select_plot.ygrid.grid_line_color = None range_tool = RangeTool(x_range=detailed_plot.x_range) range_tool.overlay.fill_color = "navy" range_tool.overlay.fill_alpha = 0.2 select_plot.add_tools(range_tool) show(column(detailed_plot, select_plot)) ``` -------------------------------- ### Wedge Glyph Example Source: https://docs.bokeh.org/en/latest/docs/reference/models/glyphs/wedge.html Renders wedges with specified x, y, radius, start and end angles, and fill color. Requires numpy and bokeh.io imports. ```python import numpy as np from bokeh.io import curdoc, show from bokeh.models import ColumnDataSource, Grid, LinearAxis, Plot, Wedge N = 9 x = np.linspace(-2, 2, N) y = x**2 r = x/15.0+0.3 source = ColumnDataSource(dict(x=x, y=y, r=r)) plot = Plot( title=None, width=300, height=300, min_border=0, toolbar_location=None) glyph = Wedge(x="x", y="y", radius="r", start_angle=0.6, end_angle=4.1, fill_color="#b3de69") plot.add_glyph(source, glyph) xaxis = LinearAxis() plot.add_layout(xaxis, 'below') yaxis = LinearAxis() plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) curdoc().add_root(plot) show(plot) ``` -------------------------------- ### Initialize a new Bokeh extension interactively Source: https://docs.bokeh.org/en/latest/docs/user_guide/advanced/extensions.html Run this command to create and customize a new pre-built Bokeh extension step by step through an interactive process. ```bash bokeh init --interactive ``` -------------------------------- ### Define Range Class with Float Properties Source: https://docs.bokeh.org/en/latest/docs/reference/core/property/descriptors.html This example shows how to define a simple Range class inheriting from Model and using Float descriptors for 'start' and 'end' properties. ```python from bokeh.model import Model from bokeh.core.properties import Float class Range(Model): start = Float(help="start point") end = Float(help="end point") ``` -------------------------------- ### WSHandler.open Source: https://docs.bokeh.org/en/latest/docs/reference/server/views.html Initialize a connection to a client. ```APIDOC ## WSHandler.open ### Description Initialize a connection to a client. ### Parameters None ### Response None ``` -------------------------------- ### Create and Show an Arc Glyph Source: https://docs.bokeh.org/en/latest/docs/reference/models/glyphs/arc.html This example demonstrates how to create an Arc glyph with specified radius, start and end angles, and line properties, then add it to a Bokeh plot and display it. ```python import numpy as np from bokeh.io import curdoc, show from bokeh.models import Arc, ColumnDataSource, Grid, LinearAxis, Plot N = 9 x = np.linspace(-2, 2, N) y = x**2 r = x/15.0+0.3 source = ColumnDataSource(dict(x=x, y=y, r=r)) plot = Plot( title=None, width=300, height=300, min_border=0, toolbar_location=None) glyph = Arc(x="x", y="y", radius="r", start_angle=0.6, end_angle=4.1, line_color="#beaed4", line_width=3) plot.add_glyph(source, glyph) xaxis = LinearAxis() plot.add_layout(xaxis, 'below') yaxis = LinearAxis() plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) curdoc().add_root(plot) show(plot) ``` -------------------------------- ### Customize Grid Band Fill Source: https://docs.bokeh.org/en/latest/docs/examples/styling/plots/grid_band_fill.html This example shows how to customize the fill color and alpha of y-grid bands. It also demonstrates removing x-grid lines. Ensure Bokeh is installed and imported. ```python from bokeh.plotting import figure, show p = figure(width=400, height=400) p.scatter([1,2,3,4,5], [2,5,8,2,7], size=10) # change just some things about the x-grid p.xgrid.grid_line_color = None # change just some things about the y-grid p.ygrid.band_fill_alpha = 0.1 p.ygrid.band_fill_color = "navy" show(p) ``` -------------------------------- ### Build with Local BokehJS (Windows CMD) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/documentation.html Builds the documentation using a local version of BokehJS. Sets the BOKEH_DOCS_CDN environment variable and then builds HTML and serves. ```batch set BOKEH_DOCS_CDN=local make.bat html make.bat serve ``` -------------------------------- ### CumSum Expression Example Source: https://docs.bokeh.org/en/latest/docs/reference/models/expressions.html Illustrates the usage of the `CumSum` expression to cumulatively sum values from a single column in a `ColumnDataSource`. The `include_zero` parameter controls whether zero is included at the start of the result. ```python source = ColumnDataSource(data=dict(foo=[1, 2, 3, 4])) CumSum(field='foo') # -> [1, 3, 6, 10] CumSum(field='foo', include_zero=True) ``` -------------------------------- ### Start Bokeh static server for development (Linux/macOS) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/setup.html Initiate a local Bokeh server to serve development resources. This is the first step when using the 'server-dev' option for BOKEH_RESOURCES. ```bash BOKEH_DEV=true bokeh static ``` -------------------------------- ### Basic Vertical Bar Chart Example Source: https://docs.bokeh.org/en/latest/docs/user_guide/basic/bars.html Generates a basic vertical bar chart displaying fruit counts. It configures the plot with a categorical x-axis, removes grid lines, and sets the y-axis start to zero. ```python from bokeh.plotting import figure, show fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries'] counts = [5, 3, 4, 2, 4, 6] p = figure(x_range=fruits, height=350, title="Fruit Counts", toolbar_location=None, tools="") p.vbar(x=fruits, top=counts, width=0.9) p.xgrid.grid_line_color = None p.y_range.start = 0 show(p) ``` -------------------------------- ### Equivalent CustomJS for Range Slider js_link Source: https://docs.bokeh.org/en/latest/docs/reference/models/expressions.html This shows the `CustomJS` callback equivalent to the `js_link` example for a range slider and plot x-range. It explicitly sets the 'start' property of the x-range using the first value from the slider. ```python from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code='other.start = this.value[0]')) ``` -------------------------------- ### Start Bokeh static server for development (Windows CMD) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/setup.html Initiate a local Bokeh server to serve development resources. This is the first step when using the 'server-dev' option for BOKEH_RESOURCES. ```cmd set BOKEH_DEV=true bokeh static ``` -------------------------------- ### Creating and Displaying HStrip Glyphs Source: https://docs.bokeh.org/en/latest/docs/reference/models/glyphs/hstrip.html This example demonstrates how to create a ColumnDataSource with y-coordinates, instantiate an HStrip glyph with specified fill color and y-coordinates, add it to a plot, configure axes and grids, and finally display the plot. Ensure Bokeh is installed and configured for display. ```python import numpy as np from bokeh.core.properties import field from bokeh.io import curdoc, show from bokeh.models import ColumnDataSource, Grid, HStrip, LinearAxis, Plot, Range1d N = 9 y0 = np.linspace(-9, 9, N) y1 = [y + 0.2*(i + 1) for i, y in enumerate(y0)] source = ColumnDataSource(dict(y0=y0, y1=y1)) plot = Plot( x_range=Range1d(start=-10, end=10), title=None, width=300, height=300, min_border=0, toolbar_location=None, ) glyph = HStrip(y0=field("y0"), y1=field("y1"), fill_color="#7fc97f") plot.add_glyph(source, glyph) xaxis = LinearAxis() plot.add_layout(xaxis, "below") yaxis = LinearAxis() plot.add_layout(yaxis, "left") plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) curdoc().add_root(plot) show(plot) ``` -------------------------------- ### Run Standalone Example (Linux/macOS) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/setup.html Execute a standalone Bokeh example on Linux or macOS. Ensure the BOKEH_RESOURCES environment variable is set to 'inline' or 'absolute-dev'. ```bash BOKEH_RESOURCES=inline python examples/basic/data/transform_markers.py ``` -------------------------------- ### Build HTML Documentation (Linux/macOS) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/documentation.html Builds the HTML output for Bokeh's documentation using the standard make command. ```bash make html ``` -------------------------------- ### Python Setup for Custom DrawTool Source: https://docs.bokeh.org/en/latest/docs/user_guide/advanced/extensions/tool.html This Python code sets up a Bokeh plot and integrates the custom DrawTool. It initializes a ColumnDataSource, creates a figure, adds the custom tool, and renders a line using the data from the source. This is the main entry point for running the example. ```python from bokeh.core.properties import Instance from bokeh.models import ColumnDataSource, Tool from bokeh.plotting import figure, show from bokeh.util.compiler import TypeScript CODE = """ import {GestureTool, GestureToolView} from "models/tools/gestures/gesture_tool" import {ColumnDataSource} from "models/sources/column_data_source" import {PanEvent} from "core/ui_events" import * as p from "core/properties" export class DrawToolView extends GestureToolView { declare model: DrawTool // this is executed when the pan/drag event starts _pan_start(_e: PanEvent): void { this.model.source.data = {x: [], y: []} } // this is executed on subsequent mouse/touch moves _pan(e: PanEvent): void { const {frame} = this.plot_view const {sx, sy} = e if (!frame.bbox.contains(sx, sy)) return const x = frame.x_scale.invert(sx) const y = frame.y_scale.invert(sy) const {source} = this.model source.get_array("x").push(x) source.get_array("y").push(y) source.change.emit() } // this is executed then the pan/drag ends _pan_end(_e: PanEvent): void {} } export namespace DrawTool { export type Attrs = p.AttrsOf export type Props = GestureTool.Props & { source: p.Property } } export interface DrawTool extends DrawTool.Attrs {} export class DrawTool extends GestureTool { declare properties: DrawTool.Props declare __view_type__: DrawToolView constructor(attrs?: Partial) { super(attrs) } tool_name = "Draw Tool" tool_icon = "bk-tool-icon-lasso-select" event_type = "pan" as "pan" default_order = 12 static { this.prototype.default_view = DrawToolView this.define(({Ref}) => ({ source: [ Ref(ColumnDataSource) ], })) } } " class DrawTool(Tool): __implementation__ = TypeScript(CODE) source = Instance(ColumnDataSource) source = ColumnDataSource(data=dict(x=[], y=[])) plot = figure(x_range=(0,10), y_range=(0,10), title="Click and drag to draw", background_fill_color="#efefef", tools="") plot.add_tools(DrawTool(source=source)) plot.line('x', 'y', line_width=3, source=source) show(plot) ``` -------------------------------- ### Build HTML Documentation (Windows CMD) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/documentation.html Builds the HTML output for Bokeh's documentation using the make.bat script in the Command Prompt. ```batch make.bat html ``` -------------------------------- ### Create and Display Tabs with Multiple Figures Source: https://docs.bokeh.org/en/latest/docs/reference/models/layouts.html This example demonstrates how to create two Tabs widgets, each containing different Bokeh figures. It shows how to add tooltips to individual tab panels and display them side-by-side using a Row layout. Ensure Bokeh is installed and run this script to see the interactive output. ```python from bokeh.models import TabPanel, Tabs, Tooltip from bokeh.models.layouts import Row from bokeh.plotting import figure, show p1 = figure(width=300, height=300) p1.scatter([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5) p2 = figure(width=300, height=300) p2.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=3, color="navy", alpha=0.5) p3 = figure(width=300, height=300) p3.scatter([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5) p4 = figure(width=300, height=300) p4.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=3, color="navy", alpha=0.5) tabs0 = Tabs(tabs=[ TabPanel(child=p1, title="circle"), TabPanel(child=p2, title="line"), ]) tabs1 = Tabs(tabs=[ TabPanel(child=p1, title="circle", tooltip=Tooltip(content="This is the first tab.", position="bottom_center")), TabPanel(child=p2, title="line", tooltip=Tooltip(content="This is the second tab.", position="bottom_center")), ]) show(Row(tabs0, tabs1)) ``` -------------------------------- ### Install Bokeh with Conda Source: https://docs.bokeh.org/en/latest/docs/first_steps.html Use this command to install Bokeh using conda. This requires Anaconda or Miniconda to be installed. ```bash conda install bokeh ``` -------------------------------- ### Serve a Bokeh App Directory Source: https://docs.bokeh.org/en/latest/docs/user_guide/server/app.html Command to start a Bokeh server application from a specified directory. ```bash bokeh serve --show myapp ``` -------------------------------- ### Navigate to Documentation Directory Source: https://docs.bokeh.org/en/latest/docs/dev_guide/documentation.html Changes the current directory to the Bokeh documentation source files. ```bash cd docs/bokeh/ ``` -------------------------------- ### Install Bokeh with Pip Source: https://docs.bokeh.org/en/latest/docs/first_steps.html Use this command to install Bokeh using pip. Ensure you have Python 3.10 or above installed. ```bash pip install bokeh ``` -------------------------------- ### Install Selenium and geckodriver with conda Source: https://docs.bokeh.org/en/latest/docs/user_guide/output/export.html Installs Selenium and geckodriver using conda for Firefox compatibility. Ensure Firefox is also installed. ```bash conda install selenium geckodriver -c conda-forge ``` -------------------------------- ### Basic BokehJS Plot Setup and Interactivity Source: https://docs.bokeh.org/en/latest/docs/user_guide/advanced/bokehjs.html Demonstrates importing BokehJS libraries, creating a plot with tools, adding a line glyph, and dynamically adding data points via a button click. ```javascript ``` -------------------------------- ### Install Selenium with pip Source: https://docs.bokeh.org/en/latest/docs/user_guide/output/export.html Installs the Selenium library using pip. You will need to manually download and install geckodriver and ensure it's in your PATH. ```bash pip install selenium ``` -------------------------------- ### Create and Show PreText Model Source: https://docs.bokeh.org/en/latest/docs/reference/models/widgets/markups.html This example demonstrates how to create a PreText model with specified text content, width, and height, and then display it using bokeh.io.show. Ensure bokeh.io is imported. ```python from bokeh.io import show from bokeh.models import PreText pre = PreText(text="""Your text is initialized with the 'text' argument. The remaining Paragraph arguments are 'width' and 'height'. For this example, those values are 500 and 100, respectively.""", width=500, height=100) show(pre) ``` -------------------------------- ### Build with Local BokehJS (Windows PowerShell) Source: https://docs.bokeh.org/en/latest/docs/dev_guide/documentation.html Builds the documentation using a local version of BokehJS. Sets the BOKEH_DOCS_CDN environment variable and then builds HTML and serves. ```powershell $Env:BOKEH_DOCS_CDN = "local" .\make.bat html .\make.bat serve ``` -------------------------------- ### StartEnd Enumeration Source: https://docs.bokeh.org/en/latest/docs/reference/core/enums.html Specifies a start or end value. Options are start and end. ```python StartEnd _ = Enumeration(start, end)_# ``` -------------------------------- ### Install and Enable jupyter-server-proxy Source: https://docs.bokeh.org/en/latest/docs/user_guide/output/jupyter.html Install the jupyter-server-proxy package and enable its server extension for JupyterLab. ```bash pip install jupyter-server-proxy && jupyter server extension enable --py jupyter-server-proxy ``` -------------------------------- ### Initialize a new Bokeh extension Source: https://docs.bokeh.org/en/latest/docs/user_guide/advanced/extensions.html Use this command to create the necessary files for a new pre-built Bokeh extension, including configuration files like `bokeh.ext.json`, `package.json`, and `tsconfig.json`. ```bash bokeh init ``` -------------------------------- ### Install jupyter_bokeh with Pip Source: https://docs.bokeh.org/en/latest/docs/user_guide/output/jupyter.html Install the jupyter_bokeh extension using pip for use with JupyterLab. ```bash pip install jupyter_bokeh ``` -------------------------------- ### Clone Bokeh Tutorial Repository Source: https://docs.bokeh.org/en/latest/docs/user_guide/output/jupyter.html Clone the bokeh-tutorial repository to access example notebooks for various Bokeh features, including notebook integration. ```git git clone https://github.com/bokeh/tutorial.git ``` -------------------------------- ### DirectoryHandler.__init__() Source: https://docs.bokeh.org/en/latest/docs/reference/application/handlers/directory.html Initializes the DirectoryHandler with a path to the application directory and optional command-line arguments. ```APIDOC ## DirectoryHandler.__init__() ### Description Initializes the handler for a given application directory. ### Parameters #### filename (str) A path to an application directory with either "main.py" or "main.ipynb". #### argv (list[str], optional) A list of string arguments to make available as sys.argv to main.py. Defaults to [] ```