Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if the app is running at local or on server? (R Shiny)

Tags:

r

shiny

I test my app on my laptop, and then deploy it to shinyapps server. Before deploying, I need to remove the statement setting the path, e.g.,

setwd('/Users/MrY/OneDrive/Data')

Is there a way the code can find out if it's running locally or on server, so that it will be like:

if (isLocal()) {
       setwd('/Users/MrY/OneDrive/Data')
}

A trivial sample code (it will fail on server if setwd isn't removed):

server.R

library(shiny)

setwd('/Users/Yuji/OneDrive/Data/TownState')  

data = 'data1.csv'  # to test, using an empty .csv file

shinyServer(function(input, output) {


}) 

ui.R

library(shiny)

shinyUI(pageWithSidebar(
    headerPanel("Click the button"),

    sidebarPanel(
        actionButton("goButton", "Go!")
    ),
    mainPanel(

    )
))
like image 295
YJZ Avatar asked Jul 15 '15 06:07

YJZ


1 Answers

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') == ""
like image 181
Vincent Avatar answered Nov 16 '22 00:11

Vincent