Rendering Shiny apps in Jupyter Notebook cells

Hi all,

I’m learning Shiny for Python to hopefully put together some simple dashboards for data visualization drawing on netcdf archives via xarray. I do most of my analytical work in notebooks, so I’ve been using them to try to figure out Shiny as well- I know it’s not suitable for ‘finished products’, but it allows me to take notes as I go.

Anyhow, I’m missing something obvious, as the Shiny app never produces any inline output in the notebook cell.

Using a trivial example:

from shiny import App, render, ui

#UI:

app_ui = ui.page_fluid(
ui.input_slider(“n”, “Select a value”, 0, 100, 20),
ui.output_text_verbatim(“txt”),
)

#server:

def server(input, output, session):
@render.text*
def txt():
return f"The slider value is: {input.n()}"*

#make app & run

app = App(app_ui, server)
app

I’ve set the notebook in question to ‘trusted’, but the code above still only evaluates the object but does not display it. The only output is:

<shiny._app.App at “some memory address”>

Anybody have any thoughts on where I’m going wrong? This is going to be one of those things that’s really obvious in hindsight and totally baffling until then.

thanks!

You can read the first part my answer here about streamlit and substitute in ‘shiny’.
There is a way to add the shiny app to your JupyterHub as a different URL: GitHub - ryanlovett/jupyter-shiny-proxy: Jupyter extension for proxying shiny server · GitHub . But you may not be using JupyterHub.

You are supposed to be able to run Shiny express mode in Jupyter to get some functionality; however, the syntax looks quite different from the examples I see so that won’t be much to help with you learning shiny.

You should be able to use an iframe to show your app in Jupyter; your app with the shiny server would be started up independently in your terminal and then just viewed in the iframe inside Jupyter. Shiny, in this case, would be alongside Jupyter.

If you need an easy place to test your Shiny dashboard/app code, check https://py.cafe/ and look at the Shiny example.