Note that in a notebook context we cannot use pull_session but this example demonstrates how we can embed the Bokeh server inside a simple flask app. ![]() id, url = ' ) # use the script in the rendered page return render_template ( "embed.html", script = script, template = "Flask" ) if _name_ = '_main_' : # runs app in debug mode app. route ( '/' ) def index (): with pull_session ( url = " ) as session : # generate a script to load the customized session script = server_session ( session_id = session. This in itself is sufficient to make the plot servable using bokeh serve:įrom bokeh.client import pull_session from bokeh.embed import server_session from flask import Flask, render_template from flask import send_from_directory app = Flask ( _name_ ) # locally creates a page. It is also possible to create a Bokeh Document more directly working with the underlying Bokeh representation instead. ipynb file can be made into a valid Panel/Bokeh app, which can be served with panel serve example.ipynb. Note also that we can also deploy an app directly from a notebook. In just a few steps we can iteratively refine in the notebook to a deployable Panel app. DynamicMap ( selected_info, streams = ) pn. opts ( color = 'red' ) layout = points + hv. mean ( axis = 0 )) else : label = 'No selection' return points. array () if index : label = 'Mean x, y: %.3f, %.3f ' % tuple ( arr. Selection1D ( source = points ) def selected_info ( index ): arr = points. Import numpy as np import panel as pn import holoviews as hv import points = hv. Therefore we will start by getting a hold of a BokehRenderer: When working with Bokeh server or wanting to manipulate a backend specific plot object you will have to use a HoloViews Renderer directly to convert the HoloViews object into the backend specific representation. opts ( tools = ) + selected_points layout DynamicMap ( selected_info, streams = ) layout = points. opts ( color = 'red' ) # Combine points and DynamicMap selected_points = hv. Selection1D ( source = points ) # Write function that uses the selection indices to slice points and compute stats def selected_info ( index ): arr = points. randn ( 1000, 2 )) # Declare points as source of selection stream selection = hv. Here we will create a small interactive plot, using Linked Streams, which mirrors the points selected using box- and lasso-select tools in a second plot and computes some statistics: Once you have developed a visualization or dashboard that you would like to deploy you can use the BokehRenderer to export the visualization as illustrated above, or you can deploy it as a Bokeh server app. The most convenient way to work with HoloViews is to iteratively improve a visualization in the notebook. This intermediate representation is then rendered as an image or as HTML with associated Javascript, which is what ends up being displayed. In other words, when a HoloViews object is evaluated a backend specific Renderer converts the HoloViews object into Bokeh models, a Matplotlib figure or a Plotly graph. If you have read a bit about HoloViews you will know that HoloViews objects are not themselves plots, instead they contain sufficient data and metadata allowing them to be rendered automatically in a notebook context. ![]() Starting a server interactively and open it in a new browser window.Ĭombining HoloViews and Bokeh models to create a more customized app In this guide we will cover how we can deploy a Bokeh app from a HoloViews plot in a number of different ways: Using periodic and timeout events to drive plot updatesĬombining HoloViews plots with custom Bokeh plots to quickly write highly customized apps. ![]() ![]() Generating and interacting with plots via the usual widgets that HoloViews supports for HoloMap and DynamicMap objects. Responding to plot events and tool interactions via Linked Streams The Bokeh server allows all the usual interactions that HoloViews lets you define and more including: Luckily, when you need a live Python process during the visualization, the Bokeh server provides a very convenient way of deploying HoloViews plots and interactive dashboards in a scalable and flexible manner. Anything with DynamicMap requires a live, running Python server to dynamically select and provide the data for the various parameters that can be selected by the user. Unfortunately, a static approach like this cannot support any HoloViews object that uses DynamicMap (either directly or via operations that return DynamicMaps like decimate, datashade, and rasterize). it is fully self-contained and does not require any Python server to be installed or running. This command will generate a file out.html that you can put on any web server, email directly to colleagues, etc.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |