我下面有一个闪亮的应用程序,在该应用程序中,我希望能够单击单个列,然后仅使用此单元格创建第二个数据表。问题是我无法通过行选择来实现这一点,因为行选择会返回用于子集的行索引。在这种情况下,我以第一行-3rd列为例。
library(shiny)
fluidPage(
title = 'Select Table Rows',
h1('A Server-side Table'),
fluidRow(
column(9, DT::dataTableOutput('x3')),
column(3, DT::dataTableOutput('x4'))
)
)
#server.r
library(shiny)
library(DT)
shinyServer(function(input, output, session) {
# server-side processing
mtcars2 = mtcars[, 1:8]
output$x3 = DT::renderDataTable(mtcars2, server = TRUE,selection=list(target='cell'))
# print the selected indices
output$x4 = DT::renderDataTable({
if(as.character(input$x3_cells_selected)=="1, 3"){
mtcars[1,3]
}
})
})
答案 0 :(得分:1)
这就是您需要的-
library(shiny)
library(DT)
ui <- fluidPage(
title = 'Select Table Rows',
h1('A Server-side Table'),
fluidRow(
column(9, DT::dataTableOutput('x3')),
column(3, DT::dataTableOutput('x4'))
)
)
#server.r
server <- function(input, output, session) {
# server-side processing
mtcars2 = mtcars[, 1:8]
output$x3 = DT::renderDataTable(mtcars2, server = TRUE,
selection=list(target='cell'))
# print the selected indices
output$x4 = DT::renderDataTable({
req(input$x3_cells_selected)
mtcars[input$x3_cells_selected[,1], input$x3_cells_selected[,2], drop = F]
})
}
shinyApp(ui, server)