Calling a web server inside Jupyterhub without connection failed

痴心易碎 提交于 2019-12-23 04:27:08

问题


My question is : How this Shiny R code mini web server in JupyterHub could work outside this server (i.e. <> localhost) ?

ui <- fluidPage(
    textInput("caption", "Caption", "Data Summary"),
    verbatimTextOutput("value")
)

server <- function(input, output) {
    output$value <- renderText({ input$caption })
}

shinyApp(ui, server)
Listening on http://127.0.0.1:4844

It works on the local server (127.0.0.1:4844) , but I doesn't work on http://192.168.x.x:4844

For information. I've installed Jupyter and Jupyter Hub, with R Kernel, on Ubuntu 16.04 xenial. I've also installed Shiny Server and RStudio Server. Everything works fine. My firewall is off and I have Apache2.

I've seen this error on an other mini web server called from Jupyterhub in other mean that Shiny. The same code works in Rstudio Server IDE.

The problem is in the configuration of Jupyter Hub or Shiny Server or in Apache 2 or elsewhere ?

"You are using Jupyter notebook. The version of the notebook server is: 5.4.0 The server is running on this version of Python: Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19) [GCC 7.2.0])".

Thanks in advance.


回答1:


Shiny apps listen on 127.0.0.1 (localhost) by default, which only the local machine can access. To make an app accessible to other machines, you can set the host option to 0.0.0.0:

options(shiny.host = "0.0.0.0")

or

runApp(host = "0.0.0.0")

See https://shiny.rstudio.com/reference/shiny/latest/runApp.html for more details.




回答2:


From @greg L comment. With ShinyApp() wrapped in RunApp() with host="0.0.0.0".

ui <- fluidPage(
    textInput("caption", "Caption", "Data Summary"),
    verbatimTextOutput("value")
)

server <- function(input, output) {
    output$value <- renderText({ input$caption })
}

runApp(shinyApp(ui, server),host = "0.0.0.0")

gave

Listening on http://0.0.0.0:6596

With http://192.168.x.x:my_port

  • 192.168.x.x : the Shiny Server host
  • my_port: the port given at the launch


来源:https://stackoverflow.com/questions/53116245/calling-a-web-server-inside-jupyterhub-without-connection-failed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!