Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whether to write in "ui.R + server.R" or "app.R"

Tags:

r

shiny

We can write our Shiny code in two separate files, "ui.R" and "server.R", alternatively we can write both the modules in a single file "app.R" and call the function shinyApp()

Is there any benefit regarding performance with either of the two approaches or we should choose one based on whether we want concise code or differentiated one?

like image 437
Pritesh Ranjan Avatar asked Jul 17 '15 13:07

Pritesh Ranjan


People also ask

Does a Shiny app have to be named app R?

to load an application. The app file does not have to be named app.

What does the UI R file in R contain?

A simple shiny app is a directory containing two R scripts, one is ui. R , which controls the layout and appearance of your app, the other is server. R , which contains the instructions that your computer needs to build your app. Note that the names for the scripts are fixed, you should NOT use other names.

Who uses R Shiny?

What do Viacom, Ubisoft, and Bank of America have in common? Hint: they are Fortune 500 companies with R Shiny in their tech stack. It's also no coincidence that they are all using open source packages for Shiny app development created at Appsilon.


2 Answers

They achieve the same thing. I usually like to write my real apps, that have lots of code and are complex, as two separate files to separate the logic and make it more maintainable. But when dealing with tiny apps for demo purposes or when posting an app to Stack Overflow or anywhere else, I find it's more reproducible and easier to have one statement (the app.R) approach.

Personal preference, really.

like image 159
DeanAttali Avatar answered Oct 09 '22 08:10

DeanAttali


I think that app.R is better, but it's better to include your source files as the UI and server respectively, with source("file.R", local=TRUE). This way, you can separate the app into more than just 2 files while having an "overall" view of the app through the main file, like a main.cpp file in C++.

like image 24
CinchBlue Avatar answered Oct 09 '22 09:10

CinchBlue