Skip to content

Can't render bokeh figure (jupyter_bokeh.js import fails) #210

@yreynaud

Description

@yreynaud

Hello,

I met an issue trying to plot a bokeh figure in a shiny app. Indeed, the jupyter_bokeh.js GET request failed (404 error).
I already downloaded shinywidgets, bokeh, jupyter_bokeh.

I tried the the ipywidget example (https://github.com/rstudio/py-shinywidgets/blob/main/examples/ipywidgets/app.py) and it worked; so maybe the problem is only for bokeh (I also arrived to plot plotly figures).

The problem doesn't come from the widget itself, because the plot works in a jupyter notebook.

I don't know if it is an environment issue (like explained here : https://shiny.posit.co/py/docs/jupyter-widgets.html#troubleshooting )
Here are the concerned libraries versions :

  • shinywidgets : 0.3.3
  • shiny : 1.0.0
  • bokeh : 3.4.3
  • jupyter_bokeh : 4.0.5

Here is a Minimal Reproducible Example (MRE):

from shiny import *
from shiny import (
    ui,
    Inputs,
    Outputs,
    Session,
    App,
)
from shinywidgets import output_widget, render_bokeh
from starlette.applications import Starlette
from starlette.routing import Mount


panel_sidebar = []
panel_main = [
    output_widget("figure_bokeh", fill=True, fillable=True)
]

app_ui = ui.page_fluid(
    ui.layout_sidebar(
                ui.sidebar(
                    *panel_sidebar,
                    open='open',
                    position='left'
                ),
                *panel_main
            ),
)

def server(input: Inputs, output: Outputs, session: Session):
    @output
    @render_bokeh
    def figure_bokeh():
        from bokeh.plotting import figure

        x = [1, 2, 3, 4, 5]
        y = [6, 7, 2, 4, 5]
        p = figure(title="Simple line example", x_axis_label="x", y_axis_label="y")
        p.line(x, y, legend_label="Temp.", line_width=2)
        return p


app = App(app_ui, server, debug=True)

routes = [
    Mount('/anonymous', app=app),
]

app = Starlette(routes=routes)

Here is the error notification that appears on the page :
image

In the logs, A message says that the .js file was not found :
INFO: 172.30.0.5:43362 - "GET /anonymous/%40bokeh/jupyter_bokeh.js HTTP/1.1" 404 Not Found

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions