2 Basic UI
2.2.8 Exercises
Provide
value
parameter:textInput("name", value = "Your name")
?shiny::sliderInput()
library(shiny)
ui <- fluidPage(
sliderInput(inputId = "user_input",
label = "User Input",
value = 10,
min = 0, max = 100,
step = 5,
# Added animation
animate = animationOptions(
interval = 1000,
loop = TRUE,
playButton = NULL,
pauseButton = NULL
)
)
)
server <- function(input, output, session) {}
shinyApp(ui, server)
-
selectInput()
documentation:
It’s also possible to group related inputs by providing a named list whose elements are (either named or unnamed) lists, vectors, or factors. In this case, the outermost names will be used as the group labels (leveraging the <optgroup>
HTML tag) for the elements in the respective sublist. See the example section for a small demo of this feature.
2.3.5 Exercises
-
renderPrint(summary(mtcars))
should be paired withverbatimTextOutput
since it is console output. -
renderText("Good morning!")
should be paired withtextOutput
since it is regular text. -
renderPrint(t.test(1:5, 2:6))
should be paired withverbatimTextOutput
since it is console output. -
renderText(str(lm(mpg ~ wt, data = mtcars)))
should be paired withverbatimTextOutput
since it is console output.
library(shiny)
ui <- fluidPage(
plotOutput("plot", width = "700px", height = "300px")
)
server <- function(input, output, session) {
output$plot <- renderPlot(plot(1:5), res = 96,
alt = "Scatterplot of 5 random numbers")
}
shinyApp(ui, server)
library(shiny)
ui <- fluidPage(
dataTableOutput("table")
)
server <- function(input, output, session) {
output$table <- renderDataTable(mtcars,
options = list(pageLength = 5,
ordering = FALSE,
searching = FALSE))
}
shinyApp(ui, server)