2016-10-13 14 views
3

My Shiny AppがDTフレームをDT aka DataTablesにレンダリングします。Shiny DTでクリックしたセルの隣にセルの値を取得

> print(unlist((input$renderMpaDtOutput_cell_clicked )))

リターンという名前のリストオブジェクト::

row col value 1 9 3929

しかし、私例えば

_cell_clicked

:私は接尾辞を追加することにより、クリックしたセルの値を取得する方法を知っていますクリックされたセルの隣にセルの値を取得する(たとえば、上記の座標の隣にinates:(row,col) = (1,9))。

アイデア?

答えて

2

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) 

enter image description here

関連する問題