Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Markdown with Shiny Server change host parameter

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.

like image 716
Andrei Avatar asked Sep 10 '14 12:09

Andrei


2 Answers

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.

like image 137
Jonathan Avatar answered Nov 09 '22 13:11

Jonathan


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

Sys.setenv(TZ = "UTC")  # for Timezone
options(shiny.port = 9999)
like image 40
RKC Avatar answered Nov 09 '22 12:11

RKC