使用闪亮的数据表获取所选单元格的数据(Get data of selected cell using Data Tables in shiny)

编程入门 行业动态 更新时间:2024-10-22 11:40:31
使用闪亮的数据表获取所选单元格的数据(Get data of selected cell using Data Tables in shiny)

我有一个Shiny的数据表,我需要从单元格中获取数据以显示正确的输出。

通过使用input$tableId_cells_selected ,我能够检索表中所选单元格的位置。 这很有用,但是我还需要引用单元格中实际写入输出函数的内容。

我发现这个链接可能会有所帮助,但是我无法将功能应用到我的Shiny服务器功能中。

任何帮助表示赞赏。

I have a data table in Shiny where I need to get the data out of the cell in order to display the proper output.

By using input$tableId_cells_selected, I am able to retrieve the location of the selected cell in the table. This is helpful, however I also need to reference what is actually in the cell to write an output function.

I found this link which may be helpful, but I was not able to apply the functionality to actually work in my Shiny server function.

Any help is appreciated.

最满意答案

这是您的解决方案:

library(shiny) library(DT) shinyApp( ui = fluidPage(DT::dataTableOutput('tableId'), textOutput("celltext")), server = function(input, output) { output$tableId = DT::renderDataTable( iris, , selection = list(target = 'cell') ) output$celltext <- renderText({ cell <- input$tableId_cells_selected iris <- iris[cell] }) } )

使用textOutput下面的数据表,您可以看到所选单元格的值...

您需要做的唯一事情是使用input$tableId_cells_selected参数来对数据进行子集化:

cell <- input$tableId_cells_selected iris <- iris[cell]

下次请发布可重复的例子 !

Here is solution for you:

library(shiny) library(DT) shinyApp( ui = fluidPage(DT::dataTableOutput('tableId'), textOutput("celltext")), server = function(input, output) { output$tableId = DT::renderDataTable( iris, , selection = list(target = 'cell') ) output$celltext <- renderText({ cell <- input$tableId_cells_selected iris <- iris[cell] }) } )

with textOutput below data table you can see the values of the selected cell...

The only thing which you need to do is to use the input$tableId_cells_selected argument to subset the data:

cell <- input$tableId_cells_selected iris <- iris[cell]

Next time please post reproducible example!

更多推荐

本文发布于:2023-07-04 16:59:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026903.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:所选   单元格   数据表   数据   data

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!