Description Usage Arguments Details Examples
View source: R/shinybootstrap2.R
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.
1 | withBootstrap2(x, env = parent.frame(), quoted = FALSE)
|
x |
An expression to evaluate with Bootstrap 2 components. |
env |
The environment in which to evaluate |
quoted |
Treat |
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()
.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | ## 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.