How to deploy a non-single file Shiny app with a custom shinyApp() function?

Hi there,

If deploying an app.R you can put a custom shinyApp() call at the end which gets deployed ok - the below example created a Google login:

library(shiny)
library(googleAuthR)

ui <-  # ...ui stuff

server <- #server stuff

shinyApp(gar_shiny_ui(ui, login_ui = silent_auth), server)

But how do you do the same if its a multi-file Shiny app e.g. a ui.R and a server.R file? The server.R and ui.R doesn't have an object to put in shinyApp()

you can source() a an R file responsible for constructing the ui object, and similarly for the server object

1 Like

Thanks for pointing me in the right direction - in the end I made a deploy.R file with this in it:

library(shiny)
library(googleAuthR)

ui <- source("ui.R")$value
server <- source("server.R")$value

shinyApp(gar_shiny_ui(ui, login_ui = silent_auth), server)

That seems to work locally when I launch the app from the deploy.R file, but when I deploy to Shinyapps.io it does not seem to use it and goes back to the ui.R in the folder. Is there anyway to force the app to use deploy.R? I tried using appPrimaryDoc="deploy.R" but it didn't work.

e.g. tried rsconnect::deployApp(appPrimaryDoc = "deploy.R") on this folder:

list.files()
[1] "deploy.R"                           "web-client.json"
[5] "rsconnect"                          "server.R"                          
[7] "ui.R" 

Ok I got there in the end by putting the ui/server files in a directory:

list.files(recursive = TRUE)
[1] "app.R"                                                  
[4] "app/web-client.json"    
[5] "app/server.R"                              
[6] "app/ui.R"                                  
[7] "rsconnect/shinyapps.io/mark/test_shiny.dcf"

And app.R looks like:

library(shiny)
library(googleAuthR)

ui     <- source("app/ui.R", chdir = TRUE)$value
server <- source("app/server.R", chdir = TRUE)$value

shinyApp(gar_shiny_ui(ui, login_ui = silent_auth), server)