async def get(self, *args, **kwargs): session = await self.get_session() element_id = self.get_argument("bokeh-autoload-element", default=None) if not element_id: self.send_error(status_code=400, reason='No bokeh-autoload-element query parameter') return app_path = self.get_argument("bokeh-app-path", default="/") absolute_url = self.get_argument("bokeh-absolute-url", default=None) if absolute_url: server_url = '{uri.scheme}://{uri.netloc}'.format(uri=urlparse(absolute_url)) else: server_url = None resources_param = self.get_argument("resources", "default") resources = self.application.resources(server_url) if resources_param != "none" else None bundle = bundle_for_objs_and_resources(None, resources) render_items = [RenderItem(sessionid=session.id, elementid=element_id, use_for_title=False)] bundle.add(Script(script_for_render_items(None, render_items, app_path=app_path, absolute_url=absolute_url))) js = AUTOLOAD_JS.render(bundle=bundle, elementid=element_id) self.set_header("Content-Type", 'application/javascript') self.write(js)
async def handle(self, body: bytes) -> None: session = await self._get_session() element_id = self.get_argument("bokeh-autoload-element", default=None) if not element_id: raise RuntimeError("No bokeh-autoload-element query parameter") app_path = self.get_argument("bokeh-app-path", default="/") absolute_url = self.get_argument("bokeh-absolute-url", default=None) server_url: Optional[str] if absolute_url: server_url = '{uri.scheme}://{uri.netloc}/'.format(uri=urlparse(absolute_url)) else: server_url = None resources_param = self.get_argument("resources", "default") resources = self.resources(server_url) if resources_param != "none" else None bundle = bundle_for_objs_and_resources(None, resources) render_items = [RenderItem(sessionid=session.id, elementid=element_id, use_for_title=False)] bundle.add(Script(script_for_render_items(None, render_items, app_path=app_path, absolute_url=absolute_url))) js = AUTOLOAD_JS.render(bundle=bundle, elementid=element_id) await self.send_response(200, js.encode(), headers=[(b"Content-Type", b"application/javascript")])
def autoload_js_script(resources, token, element_id, app_path, absolute_url): resources = Resources.from_bokeh(resources) bundle = bundle_resources(resources) render_items = [ RenderItem(token=token, elementid=element_id, use_for_title=False) ] bundle.add( Script( script_for_render_items({}, render_items, app_path=app_path, absolute_url=absolute_url))) return AUTOLOAD_JS.render(bundle=bundle, elementid=element_id)