Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(shiny)
- ui <- fluidPage(
- mainPanel(
- actionButton("previous_q",
- "Previous"),
- actionButton("next_q",
- "Next"),
- selectInput("jump",
- "Jump to Question",
- choices = 1:10),
- textOutput("selected")
- )
- )
- server <- function(input, output) {
- # Select based on "Previous" and "Next" buttons -------
- selected <- reactiveVal(1)
- observeEvent(input$previous_q, {
- newSelection <- selected() - 1
- selected(newSelection)
- })
- observeEvent(input$next_q, {
- newSelection <- selected() + 1
- selected(newSelection)
- })
- # Jump to selection (COMMENTED OUT SO APP DOESN'T CRASH) ----------------
- #observeEvent(input$jump, {
- #newSelection <- input$jump
- #selected(newSelection)
- #})
- # Display selected
- output$selected <- renderText({
- paste(selected())
- })
- }
- shinyApp(ui = ui, server = server)
- observeEvent(input$jump, {
- newSelection <- as.integer(input$jump)
- selected(newSelection)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement