Python bokeh.embed.server_document() Examples

The following are 12 code examples of bokeh.embed.server_document(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module bokeh.embed , or try the search function .
Example #1
Source File: task_pages.py    From mars with Apache License 2.0 5 votes vote down vote up
def get(self, session_id, graph_key):
        session_name = session_id

        template = _jinja_env.get_template('task_pages/progress.html')
        task_progress_script = server_document(
            '%s://%s/%s' % (self.request.protocol, self.request.host, PROGRESS_APP_NAME),
            arguments=dict(session_id=session_id, task_id=graph_key))
        self.write(template.render(
            session_id=session_id,
            session_name=session_name,
            task_id=graph_key,
            task_progress_script=task_progress_script,
        )) 
Example #2
Source File: worker_pages.py    From mars with Apache License 2.0 5 votes vote down vote up
def get(self, endpoint):
        template = _jinja_env.get_template('worker_pages/timeline.html')
        worker_timeline_script = server_document(
            '%s://%s/%s' % (self.request.protocol, self.request.host, TIMELINE_APP_NAME),
            arguments=dict(endpoint=endpoint))
        self.write(template.render(
            endpoint=endpoint,
            host_name=_worker_host_cache.get(endpoint, endpoint),
            worker_timeline_script=worker_timeline_script,
        )) 
Example #3
Source File: views.py    From parambokeh with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def sliders(request):
    return render(request, 'base.html', {
        "server_script": server_document('http://%s:%s/bk_sliders_app'%(bk_config.server['address'],
                                                                        bk_config.server['port']))}) 
Example #4
Source File: tornado_bokeh_embed.py    From stock with Apache License 2.0 5 votes vote down vote up
def get(self):
        print("index ...")
        template = env.get_template('bokeh_embed.html')
        script = server_document(server_url + 'bkapp')
        print(script)
        self.write(template.render(script=script, template="Tornado"))
        # self.write(html_content) 
Example #5
Source File: pysdr_app.py    From pysdr with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        print("creating new app")
        self.flask_app = Flask('__main__') # use '__main__' because this script is the top level

        # GET routine for root page
        @self.flask_app.route('/', methods=['GET'])  # going to http://localhost:5006 or whatever will trigger this route
        def bkapp_page():
            script = server_document(url='http://localhost:5006/bkapp')
            return render_template('index.html', script=script) 
Example #6
Source File: server_demo.py    From pairstrade-fyp-2019 with MIT License 5 votes vote down vote up
def index():
	# format
	# name-of-js-to-add = server_document(url="http://localhost:5006/<py file that generate the graph and updates it>")
    
    client_demo_script=server_document(url="http://localhost:5006/client_demo")
    # script2=server_document(url="http://localhost:5006/update2")
    return render_template('client-demo.html', client_plot=client_demo_script) 
Example #7
Source File: views.py    From panel with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def sliders(request: HttpRequest) -> HttpResponse:
    script = server_document(request.build_absolute_uri())
    return render(request, "base.html", dict(script=script)) 
Example #8
Source File: views.py    From panel with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def gbm(request: HttpRequest) -> HttpResponse:
    script = server_document(request.build_absolute_uri())
    return render(request, "gbm/gbm.html", dict(script=script)) 
Example #9
Source File: views.py    From panel with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def stockscreener(request: HttpRequest) -> HttpResponse:
    script = server_document(request.build_absolute_uri())
    return render(request, "stockscreener/stockscreener.html", dict(script=script)) 
Example #10
Source File: views.py    From panel with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def sliders(request: HttpRequest) -> HttpResponse:
    script = server_document(request.build_absolute_uri())
    return render(request, "sliders/sliders.html", dict(script=script)) 
Example #11
Source File: jobs_table.py    From tethys with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def bokeh_row(request, job_id, type='individual-graph'):
    """
    Returns an embeded bokeh document in json. Javascript can use this method to inject bokeh document to jobs table.
    """
    try:
        job = TethysJob.objects.get_subclass(id=job_id)
        status = job.status

        # Get dashboard link for a given job_id
        scheduler_id = job.scheduler_id
        dask_scheduler = DaskScheduler.objects.get(id=scheduler_id)
        base_link = dask_scheduler.dashboard

        # Append http if not exists
        if 'http' not in base_link:
            base_link = 'http://' + base_link

        # Add forward slash if not exist
        if base_link[-1] != '/':
            base_link = base_link + '/'

        # use bokeh server_document to embed
        url_link = base_link + type
        script = server_document(url_link)

        context = {"the_script": script}
        success = True

    except Exception as e:
        log.error('The following error occurred when getting bokeh chart '
                  'from scheduler {} for job {}: {}'.format(dask_scheduler.name, job_id, str(e)))
        return

    # Render bokeh app into a string to pass in JsonResponse
    html = render_to_string('tethys_gizmos/gizmos/bokeh_application.html', context)
    return JsonResponse({'success': success, 'status': status, 'html': html}) 
Example #12
Source File: notebook.py    From panel with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def show_server(panel, notebook_url, port):
    """
    Displays a bokeh server inline in the notebook.

    Arguments
    ---------
    panel: Viewable
      Panel Viewable object to launch a server for
    notebook_url: str
      The URL of the running Jupyter notebook server
    port: int (optional, default=0)
      Allows specifying a specific port
    server_id: str
      Unique ID to identify the server with

    Returns
    -------
    server: bokeh.server.Server
    """
    from IPython.display import publish_display_data

    if callable(notebook_url):
        origin = notebook_url(None)
    else:
        origin = _origin_url(notebook_url)
    server_id = uuid.uuid4().hex
    server = get_server(panel, port=port, websocket_origin=origin,
                        start=True, show=False, server_id=server_id)

    if callable(notebook_url):
        url = notebook_url(server.port)
    else:
        url = _server_url(notebook_url, server.port)

    script = server_document(url, resources=None)

    publish_display_data({
        HTML_MIME: script,
        EXEC_MIME: ""
    }, metadata={
        EXEC_MIME: {"server_id": server_id}
    })
    return server