How to know if the app is running at local or on server? (R Shiny)
The standard way to do this in Shiny is with: Sys.getenv('SHINY_PORT')
. You could write something like:
is_local <- Sys.getenv('SHINY_PORT') == ""
EDIT 2020: There still is no official way to do this, but I would opt for Yihui's method of is_local <- Sys.getenv('SHINY_PORT') == ""
I don't know if this is the proper way or not, but you could look at the host using session$clientData$url_hostname
. When you run it locally, unless you specifically change the host, it will be 127.0.0.1
and I'm guessing on shinyapps it'll be something like shinyapps.io
. Sample code
runApp(shinyApp(
ui = fluidPage(
),
server = function(input, output, session) {
observe({
if (session$clientData$url_hostname == "127.0.0.1") {
setwd(...)
}
})
}
))
Something of that sort should work, though I can't vouch for whether or not it's the best solution