关于 R Shiny 的问题从阵容中获取 table 点击信息

Question on R Shiny gets table click information from lineups

我试图在单击列表 table 时获取 table 行信息(例如行名、编号或单元格值),但我不知道如何获取。有人可以帮忙吗?任何输入将不胜感激。

以下是我用来说明问题的示例代码

library(shiny)
library(crosstalk)
library(lineupjs)
library(magrittr)

ui <- fluidPage(
  splitLayout(
    column(12,
        lineupOutput("table1", height=300),
        textInput("val1", "Value1", "Tobeupdated1")
    ),
    column(12,
        DT::dataTableOutput("table2"),
        textInput("val2", "Value2", "Tobeupdated2")
    )
  )
)

server <- function(input, output,session) {
  dfshow <- head(iris,n=5)

  shared_iris <- SharedData$new(dfshow)
 t<-1

  output$table1 <- renderLineup({
    lineup(shared_iris)
  })

  output$table2<- DT::renderDT(dfshow, selection = 'single', rownames = FALSE,  editable = TRUE)

  observeEvent(input$table1_rows_selected,{
    rowIndex <- input$table1_rows_selected
    updateTextInput(session, "val1", value = as.character(input$table1_rows_selected))
  })

  observeEvent(input$table2_rows_selected,{
    rowIndex <- input$table2_rows_selected
    updateTextInput(session, "val2", value = as.character(input$table2_rows_selected))
  })

}
shinyApp(ui = ui, server = server)

我想要的是当我点击阵容[​​=19=]1时,我想更新table1下面的值,就像右边的那样。谢谢。

隐藏在shared_iris$selection()方法中。

做这样的事情:

library(shiny)
library(crosstalk)
library(lineupjs)
library(magrittr)

ui <- fluidPage(
    splitLayout(
        column(12,
               lineupOutput("table1", height=300),
               textInput("val1", "Value1", "Tobeupdated1")
        ),
        column(12,
               DT::dataTableOutput("table2"),
               textInput("val2", "Value2", "Tobeupdated2")
        )
    )
)

server <- function(input, output,session) {
    dfshow <- head(iris,n=5)
    
    shared_iris <- SharedData$new(dfshow)
    t<-1
    
    output$table1 <- renderLineup({
        lineup(shared_iris)
    })

    output$table2<- DT::renderDT(dfshow, selection = 'single', rownames = FALSE,  editable = TRUE)
    
    observeEvent(shared_iris$selection(),{
        rowIndex <- which(shared_iris$selection())
        updateTextInput(session, "val1", value = as.character(rowIndex))
    })
    
    observeEvent(input$table2_rows_selected,{
        rowIndex <- input$table2_rows_selected
        updateTextInput(session, "val2", value = as.character(input$table2_rows_selected))
    })
    
}
shinyApp(ui = ui, server = server)