Добро пожаловать на SO!
@ StéphaneLaurent был немного быстрее - я все равно опубликую свое решение: как он уже упоминал, вам понадобится as.integer(input$jump)
Более того, вы этого не делаетенужно reactiveVal()
"выбрано".Это также заботится об ограничении вашего выбора:
library(shiny)
selectInputChoices = 1:10
ui <- fluidPage(mainPanel(
actionButton("previous_q",
"Previous"),
actionButton("next_q",
"Next"),
selectInput(
"jump",
"Jump to Question",
choices = selectInputChoices,
selected = 1
),
textOutput("selected")
))
server <- function(input, output, session) {
# Select based on "Previous" and "Next" buttons -------
observeEvent(input$previous_q, {
req(input$jump)
if (as.integer(input$jump) > min(selectInputChoices)) {
newSelection <- as.integer(input$jump) - 1
updateSelectInput(session, inputId = "jump", selected = newSelection)
}
})
observeEvent(input$next_q, {
req(input$jump)
if (as.integer(input$jump) < max(selectInputChoices)) {
newSelection <- as.integer(input$jump) + 1
updateSelectInput(session, inputId = "jump", selected = newSelection)
}
})
# Display selected
output$selected <- renderText({
req(input$jump)
paste(input$jump)
})
}
shinyApp(ui = ui, server = server)