mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-29 03:00:45 -04:00
Add info about using shinyApp and runApp together
This commit is contained in:
@@ -11,7 +11,10 @@ runApp(appDir = getwd(), port = NULL,
|
||||
\arguments{
|
||||
\item{appDir}{The directory of the application. Should contain
|
||||
\code{server.R}, plus, either \code{ui.R} or a \code{www} directory that
|
||||
contains the file \code{index.html}. Defaults to the working directory.}
|
||||
contains the file \code{index.html}. Defaults to the working directory.
|
||||
Instead of a directory, this could be a list with \code{ui} and
|
||||
\code{server} components, or a Shiny app object created by
|
||||
\code{\link{shinyApp}}.}
|
||||
|
||||
\item{port}{The TCP port that the application should listen on. Defaults to
|
||||
choosing a random port.}
|
||||
@@ -34,12 +37,12 @@ Shiny Server Pro route requests to the correct process.}
|
||||
the value \code{"showcase"}, shows application code and metadata from a
|
||||
\code{DESCRIPTION} file in the application directory alongside the
|
||||
application. If set to \code{"normal"}, displays the application normally.
|
||||
Defaults to \code{"auto"}, which displays the application in the mode
|
||||
given in its \code{DESCRIPTION} file, if any.}
|
||||
Defaults to \code{"auto"}, which displays the application in the mode given
|
||||
in its \code{DESCRIPTION} file, if any.}
|
||||
}
|
||||
\description{
|
||||
Runs a Shiny application. This function normally does not return; interrupt
|
||||
R to stop the application (usually by pressing Ctrl+C or Esc).
|
||||
Runs a Shiny application. This function normally does not return; interrupt R
|
||||
to stop the application (usually by pressing Ctrl+C or Esc).
|
||||
}
|
||||
\details{
|
||||
The host parameter was introduced in Shiny 0.9.0. Its default value of
|
||||
@@ -68,6 +71,20 @@ runApp(list(
|
||||
output$plot <- renderPlot({ hist(runif(input$n)) })
|
||||
}
|
||||
))
|
||||
|
||||
|
||||
# Running a Shiny app object
|
||||
app <- shinyApp(
|
||||
ui = bootstrapPage(
|
||||
numericInput('n', 'Number of obs', 100),
|
||||
plotOutput('plot')
|
||||
),
|
||||
server = function(input, output) {
|
||||
output$plot <- renderPlot({ hist(runif(input$n)) })
|
||||
}
|
||||
)
|
||||
|
||||
runApp(app)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,16 +57,22 @@ file and either ui.R or www/index.html)}
|
||||
\item{...}{Additional parameters to be passed to print.}
|
||||
}
|
||||
\value{
|
||||
An object that represents the app. Printing the object will run the
|
||||
app.
|
||||
An object that represents the app. Printing the object or passing it
|
||||
to \code{\link{runApp}} will run the app.
|
||||
}
|
||||
\description{
|
||||
These functions create Shiny app objects from either an explicit UI/server
|
||||
pair (\code{shinyApp}), or by passing the path of a directory that
|
||||
contains a Shiny app (\code{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 \pkg{knitr}
|
||||
document.
|
||||
pair (\code{shinyApp}), or by passing the path of a directory that contains a
|
||||
Shiny app (\code{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 \pkg{knitr} document.
|
||||
}
|
||||
\details{
|
||||
Normally when this function is used at the R console, the Shiny app object is
|
||||
automatically passed to the \code{print()} function, which runs the app. If
|
||||
this is called in the middle of a function, the value will not be passed to
|
||||
\code{print()} and the app will not be run. To make the app run, pass the app
|
||||
object to \code{print()} or \code{\link{runApp}()}.
|
||||
}
|
||||
\examples{
|
||||
\donttest{
|
||||
@@ -81,6 +87,20 @@ shinyApp(
|
||||
)
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user