小编Lis*_* B.的帖子

在 Shiny 中检测箭头键(光标键)

我想将一个操作链接到我的 Shiny 应用程序中的箭头/光标键。该操作已与按下上一个和下一个按钮相关联。所以我想分别添加 eventExpr“光标向右”和“光标向左”。这是要策划一个又一个情节。这是 mtcars 数据集的简化示例。


datasets <- list(mtcars, iris, PlantGrowth)

ui <- fluidPage(
  mainPanel(
    titlePanel("Simplified example"),
    tableOutput("cars"),
    actionButton("prevBtn", icon = icon("arrow-left"), ""),
    actionButton("nextBtn", icon = icon("arrow-right"), ""),
    verbatimTextOutput("rows")
  )
)

server <- function(input, output) {
  output$cars <- renderTable({
    head(dat())
  })

  dat <- reactive({
    if (is.null(rv$nr)) {
      d <- mtcars
    }
    else{
      d <- datasets[[rv$nr]]
    }
  })

  rv <- reactiveValues(nr = 1)

  set_nr <- function(direction) {
    rv$nr <- rv$nr + direction
  }

  observeEvent(input$nextBtn, { # here I would like add …
Run Code Online (Sandbox Code Playgroud)

shiny

0
推荐指数
1
解决办法
444
查看次数

标签 统计

shiny ×1