When I start an R
script that runs a shiny
app from the cmd
line, it appears to launch two instances of Rscript.exe
? I can always kill the smaller of the two and the app continues to run? Can someone elaborate on what is actually going on behind the scenes or tell me what I am doing wrong that is creating double processes?
require(shiny)
app <- shinyApp(
ui = bootstrapPage(
numericInput('n', 'Number of obs', 100),
plotOutput('plot')
),
server = function(input, output) {
output$plot <- renderPlot({ hist(runif(input$n)) })
}
)
runApp(app, launch.browser = FALSE, port = 1234, host = "10.123.4.56")
Now if I launch this via the cmd
line:
START Rscript --vanilla C:\Users\Jason\Projects\super_simple.R
At this point, I can point my browser to http://10.123.4.56:1234
and see the app. However, if I look at my running processes via: tasklist /FI "imagename eq rscript*"
I see two Rscript.exe
processes:
What I've determined, however, is that I can always kill the smaller of the two (e.g., taskkill /pid 9360 /f
) and yet the app still functions in its entirety? NOTE: I have tried starting the command in the background via START \b ...
but the outcome is the same.
This is a general thing with the R scripting command-line utilities (Rscript.exe
, R.exe
, Rcmd.exe
) and not specific to Shiny. All of these actually call Rterm.exe
underneath to run the actual program in a separate process.
Try Rscript.exe
with --verbose
and you'll see what I mean:
> Rscript --verbose script.R
running
'C:\PROGRA~1\R\R-34~1.0\bin\x64\Rterm.exe --slave --no-restore --file=script.R'
You can try out the other tools and see how they behave.
For more info, check out the source code
This question has some good info as well
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With