Lifecycle for servers started by jupyter server proxy


#1

Hi all,

I’m pretty new to the jupyter ecosystem, but have enjoyed what I’ve been able to do so far, thanks to everyone who has been working on this!

I was hoping to use jupyter server proxy as a direct front end to some shiny apps I have written so that I can share them with some jupyter users (eg directly run the shiny app without using something like shiny server). I know that this is an unusual way to have a web app, but my ideal lifecycle is to have the shiny app quit when the user is not using it.

However, when I have the shiny app close, the proxy layer does not seem to start another instance of my app, instead I get a page that says [Errno 111] Connection refused.

Is there a way that I could indicate to the proxy that the app has closed and it needs to start it from scratch?

I’ve also noticed that sometimes old processes stick around after shutting down the user’s jupyter hub, which seems like it would be a problem if the app didn’t automatically close.

I’m having trouble thinking of a way to share a fully reproducible example, but here’s a shiny app that closes when it’s disconnected from:

test.r

port <- as.numeric(commandArgs(trailingOnly = TRUE)[1])

n <- 200
library(shiny)
runApp(
  port = port,
  shinyApp(
    ui = bootstrapPage(
      numericInput('n', 'Number of obs', n),
      plotOutput('plot')
    ),
    server = function(input, output, session) {
      session$onSessionEnded(function() {
        stopApp()
      })
      output$plot <- renderPlot({
        hist(runif(input$n))
      })
    }
  )
)

This R script is called from the Server Process configuration with a single argument {port}. I’ve done this with a jupyter_notebook_config.py file with the following:

c.ServerProxy.servers = {
    'test': {
        'command': ['Rscript', 'test.r', '{port}']
    }
}

#2

Have you considered checking out Binder for something like this? E.g., here’s an example repo that sets up Shiny on mybinder.org: https://github.com/binder-examples/r


#3

This is pretty great :slight_smile:

Have you looked at https://github.com/jupyterhub/jupyter-rsession-proxy for shiny? shiny likes having a config file for it, and that sets it up properly. Give that a shot?

Can you also tell me more about it leaving processes behind? What kinda processes are these?


#4

Looks very cool, but I need to run the apps on a local machine.


#5

That’s for shiny server though, I was hoping to run shiny apps just from the R command line, because shiny server seems like it’s doing essentially the same thing as jupyter server proxy (running a shiny app and proxying the port). Perhaps this is misguided though, so I’ll take a closer look at shiny server.

As for what process is being left behind, what I’m seeing is when I’m running stuff on a multi-user jupyter lab instance, after I shut down the my hub (the red “stop my server” button from my-jupter-instance.com/hub/home), the old R process is still running. If I restart the server and try to get back to the proxied URL, jupyter server proxy starts another process and proxies to that one, meaning that 2 processes are running.


#6

Oh, I think this #FIXME is talking about what I was hoping for.

Thanks again for all the great work, I’m excited to see it develop!