rstudio/shiny — pull request #563 by wch (2014-08-07 18:35:28+00:00)
Title: Single-file app support

This adds support for calling `runApp()` on a directory that contains a file `app.R`, instead of `ui.R` and `server.R`. Sourcing this file should return a shiny.appobj. For example:

```R
# Global variables can go here
n <- 200

# Define the UI
ui <- bootstrapPage(
numericInput('n', 'Number of obs', n),
plotOutput('plot')
)

# Define the server code
server <- function(input, output) {
output$plot <- renderPlot({
hist(runif(input$n))
})
}

# Return a Shiny app object
shinyApp(ui = ui, server = server)
```

*****

The changes in this PR result in a change in behavior in the errors given when there is a missing server.R or ui.R.

Previously, when an app was run in a directory that lacked both ui.R and server.R, the user would see the webpage saying that it couldn't find the UI. Now it gives this error:

```
Error in shinyAppDir(x) : App dir must contain either app.R or server.R.
```

Previously, if ui.R was present but server.R was not, then it would give an error:

```
Listening on http://127.0.0.1:3812
Warning in file(filename, "r", encoding = encoding) :
cannot open file '/Users/winston/Dropbox/Projects/shiny/test2/server.R': No such file or directory
Error in file(filename, "r", encoding = encoding) :
cannot open the connection
````

Now it gives:

```
Error in shinyAppDir(x) : App dir must contain either app.R or server.R.
```

*****

When running a directory with `app.R`, here's what happens if the ui or server is missing:

* If the `shinyApp()` call is missing `ui`, it displays the missing-UI webpage.
* If the `shinyApp()` call is missing `server`, it displays a web page saying `ERROR: `server` missing from shinyApp`

*****

Other notes:

* This supports an `app.R` with a `www/index.html` page.
* Showcase mode doesn't work yet.