daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Feb 19th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(shiny)
  2.  
  3. ui <- fluidPage(
  4.  
  5.    mainPanel(
  6.  
  7.      actionButton("previous_q",
  8.                   "Previous"),
  9.      actionButton("next_q",
  10.                   "Next"),
  11.      selectInput("jump",
  12.                  "Jump to Question",
  13.                  choices = 1:10),
  14.      textOutput("selected")
  15.  
  16.    )
  17. )
  18.  
  19. server <- function(input, output) {
  20.  
  21.   # Select based on "Previous" and "Next" buttons -------
  22.  
  23.   selected <- reactiveVal(1)
  24.  
  25.   observeEvent(input$previous_q, {
  26.  
  27.     newSelection <- selected() - 1
  28.     selected(newSelection)
  29.  
  30.   })
  31.  
  32.   observeEvent(input$next_q, {
  33.  
  34.     newSelection <- selected() + 1
  35.     selected(newSelection)
  36.  
  37.   })
  38.  
  39.   # Jump to selection (COMMENTED OUT SO APP DOESN'T CRASH) ----------------
  40.  
  41.   #observeEvent(input$jump, {
  42.  
  43.     #newSelection <- input$jump
  44.     #selected(newSelection)
  45.  
  46.   #})
  47.  
  48.   # Display selected
  49.  
  50.   output$selected <- renderText({
  51.     paste(selected())                    
  52.   })
  53. }
  54.  
  55. shinyApp(ui = ui, server = server)
  56.      
  57. observeEvent(input$jump, {
  58.  
  59.     newSelection <- as.integer(input$jump)
  60.     selected(newSelection)
  61.  
  62.   })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top