shinyApp: Create a Shiny app object

Description Usage Arguments Details Value Examples

Description

These functions create Shiny app objects from either an explicit UI/server pair (shinyApp), or by passing the path of a directory that contains a Shiny app (shinyAppDir). You generally shouldn't need to use these functions to create/run applications; they are intended for interoperability purposes, such as embedding Shiny apps inside a knitr document.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
shinyApp(ui = NULL, server = NULL, onStart = NULL,
  options = list(), uiPattern = "/", enableBookmarking = NULL)

shinyAppDir(appDir, options = list())

shinyAppFile(appFile, options = list())

as.shiny.appobj(x)

## S3 method for class 'shiny.appobj'
as.shiny.appobj(x)

## S3 method for class 'list'
as.shiny.appobj(x)

## S3 method for class 'character'
as.shiny.appobj(x)

is.shiny.appobj(x)

## S3 method for class 'shiny.appobj'
print(x, ...)

## S3 method for class 'shiny.appobj'
as.tags(x, ...)

Arguments

ui

The UI definition of the app (for example, a call to fluidPage() with nested controls)

server

A server function

onStart

A function that will be called before the app is actually run. This is only needed for shinyAppObj, since in the shinyAppDir case, a global.R file can be used for this purpose.

options

Named options that should be passed to the runApp call (these can be any of the following: "port", "launch.browser", "host", "quiet", "display.mode" and "test.mode"). You can also specify width and height parameters which provide a hint to the embedding environment about the ideal height/width for the app.

uiPattern

A regular expression that will be applied to each GET request to determine whether the ui should be used to handle the request. Note that the entire request path must match the regular expression in order for the match to be considered successful.

enableBookmarking

Can be one of "url", "server", or "disable". This is equivalent to calling the enableBookmarking() function just before calling shinyApp(). With the default value (NULL), the app will respect the setting from any previous calls to enableBookmarking(). See enableBookmarking for more information.

appDir

Path to directory that contains a Shiny app (i.e. a server.R file and either ui.R or www/index.html)

appFile

Path to a .R file containing a Shiny application

x

Object to convert to a Shiny app.

...

Additional parameters to be passed to print.

Details

Normally when this function is used at the R console, the Shiny app object is automatically passed to the print() function, which runs the app. If this is called in the middle of a function, the value will not be passed to print() and the app will not be run. To make the app run, pass the app object to print() or runApp().

Value

An object that represents the app. Printing the object or passing it to runApp will run the app.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## Only run this example in interactive R sessions
if (interactive()) {
  options(device.ask.default = FALSE)

  shinyApp(
    ui = fluidPage(
      numericInput("n", "n", 1),
      plotOutput("plot")
    ),
    server = function(input, output) {
      output$plot <- renderPlot( plot(head(cars, input$n)) )
    }
  )

  shinyAppDir(system.file("examples/01_hello", package="shiny"))


  # The object can be passed to runApp()
  app <- shinyApp(
    ui = fluidPage(
      numericInput("n", "n", 1),
      plotOutput("plot")
    ),
    server = function(input, output) {
      output$plot <- renderPlot( plot(head(cars, input$n)) )
    }
  )

  runApp(app)
}

nGanon/R_shiny documentation built on May 20, 2019, 9:42 a.m.