gpt4 book ai didi

r - 获取 Shiny DT 中单击的单元格旁边的单元格值

转载 作者:行者123 更新时间:2023-12-04 09:24:29 26 4
gpt4 key购买 nike

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

_cell_clicked
例如:
print(unlist(( input$renderMpaDtOutput_cell_clicked  )))
返回命名列表对象:
row   col value 
1 9 3929
但是我想在单击的单元格旁边获取单元格值(例如在上面的坐标旁边: (row,col) = (1,9) )。
有任何想法吗?

最佳答案

只需将坐标添加到 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

关于r - 获取 Shiny DT 中单击的单元格旁边的单元格值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40020519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com