shinybootstrap2 (version 0.2.1)

withBootstrap2: Run Shiny UI code with Bootstrap 2 elements.

Description

This function takes an expression containing calls to functions in the shinybootstrap2 package, and evaluates it in an environment where these functions will be found, even when shinybootstrap2 is not attached.

Usage

withBootstrap2(x, env = parent.frame(), quoted = FALSE)

Arguments

x
An expression to evaluate with Bootstrap 2 components.
env
The environment in which to evaluate x.
quoted
Treat x as a quoted expression. If FALSE (the default) x will be treated as an unquoted expression. If TRUE, the code should be the output of a quote().

Details

Shiny version 0.11 and above uses Bootstrap 3 instead of Bootstrap 2. The purpose of the shinybootstrap2 package is to provide backward compatibility when needed. Almost all of the functions in shinybootstrap2 have the same name as functions in shiny, but they generate HTML that works with Bootstrap 2 instead of 3.

This function should almost always be called using shinybootstrap2::withBootstrap2(), without attaching the package. In other words, library(shinybootstrap2), shouldn't appear in your code. This is because attaching the package will result in functions from shinybootstrap2 masking functions from shiny, even outside of withBootstrap2().

Examples

Run this code
## Not run: 
# library(shiny)
# 
# ## Single-file app using Bootstrap 2 ===========================
# shinybootstrap2::withBootstrap2({
#   shinyApp(
#     ui = fluidPage(
#       numericInput("n", "n", 1),
#       plotOutput("plot")
#     ),
#     server = function(input, output) {
#       output$plot <- renderPlot( plot(head(cars, input$n)) )
#     }
#   )
# })
# 
# 
# ## App with server.R and UI. R =================================
# ## ui.R
# shinybootstrap2::withBootstrap2({
#   fluidPage(
#     selectInput("ui", "Input type", choices = c("numeric", "slider")),
#     uiOutput("n_ui"),
#     plotOutput("plot")
#   )
# })
# 
# ## server.R
# # In server.R, it's only necessary to wrap code in withBoostrap2()
# # when renderUI() is used.
# shinybootstrap2::withBootstrap2({
#   function(input, output) {
#     output$n_ui <- renderUI({
#       if (input$ui == "numeric")
#         numericInput("n", "n", 1)
#       else if (input$ui == "slider")
#         sliderInput("n", "n", 1, 10, value = 1)
#     })
#     output$plot <- renderPlot( plot(head(cars, input$n)) )
#   }
# })
# 
# ## End(Not run)

Run the code above in your browser using DataLab