【问题标题】:Get cell value next to clicked cell in Shiny DT获取 Shiny DT 中单击的单元格旁边的单元格值
【发布时间】:2017-02-22 13:10:55
【问题描述】:

My Shiny App 在DT 又名DataTables 中渲染DT 帧。我知道如何通过添加后缀来获取点击单元格的值:

_cell_clicked

例如:

print(unlist(( input$renderMpaDtOutput_cell_clicked  )))

返回命名列表对象:

row   col value 
  1     9  3929

但我想获取单击单元格旁边的单元格值(例如,在上面的坐标旁边:(row,col) = (1,9))。

有什么想法吗?

【问题讨论】:

    标签: r datatables shiny cell dt


    【解决方案1】:

    只需将坐标分别添加到rowcol 值即可。获取用于创建数据表的table,获取input$dt_cell_clicked$row$col 并请求table[input$dt_cell_clicked$row + 1, input$dt_cell_clicked$col],反之亦然。示例应用:

    library(shiny)
    
    ui <- fluidPage(
     numericInput("x", "how many cells to the left/right?", min=-5, max=5, value=0),
     numericInput("y", "how many cells to the top/bottom?", min=-5, max=5, value=0),
     DT::dataTableOutput("dt"),
     uiOutput("headline"),
     verbatimTextOutput("shifted_cell")
    )
    
    server <- function(input, output) {
    
      output$headline <- renderUI({
        h3(paste0("You clicked value ", input$dt_cell_clicked$value, ". ", 
                  input$x, " cells to the ", ifelse(input$x > 0, "right", "left"), " and ",
                  input$y, " cells to the ", ifelse(input$y > 0, "bottom", "top"), " is:"))
      })
      # the value of the shifted cell
      output$shifted_cell <- renderPrint({
        mtcars[input$dt_cell_clicked$row + input$y, # clicked plus y to the bottom/top
               input$dt_cell_clicked$col + input$x] # clicked plus x to the left/right 
      })
    
      # the datatable
      output$dt <- DT::renderDataTable({
        DT::datatable(mtcars, select="none")})
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-23
      • 2017-12-17
      • 1970-01-01
      • 2017-01-21
      • 2022-06-17
      • 2018-06-04
      • 1970-01-01
      相关资源
      最近更新 更多