R Markdown with Shiny Server change host parameter

北城以北 提交于 2019-12-18 12:35:13

问题


I am running RStudio on a server and I created a RMarkdown (.Rmd) file. It works fine if I create it as a static HTML but it does not work if I want it to be interactive (by adding runtime:shiny).

The issue is that when I add runtime:shiny and press the Run Document button the application will try to open at 127.0.0.1:xxxx (here xxxx is a random port). In order to make it work I would have to be able to change the host parameter to '0.0.0.0'. This is an option in the runApp function from the shiny package but I don't know how to add this option in RMarkdown.

Can anyone help me with this?

Thank you.


回答1:


The ::run command from rmarkdown invokes shiny::runApp internally. You can set the option shiny.host before running the document:

options(shiny.host="0.0.0.0")
rmarkdown::run("myfile.Rmd")

You an also pass arbitrary paramters to runApp, so this should work too:

rmarkdown::run("myfile.Rmd", shiny_args=list(host="0.0.0.0"))

Neither of these will work with the Run Document button; that button starts a new R session in which to render the document. To change the shiny.host option in that session, you'll need to add the option to your .Rprofile.




回答2:


Set the default values you want to initialize in (~/.Rprofile) under user directory

Sys.setenv(TZ = "UTC")  # for Timezone
options(shiny.port = 9999)


来源:https://stackoverflow.com/questions/25765996/r-markdown-with-shiny-server-change-host-parameter

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