您可以使用DT 选择点击了哪些行、列、单元格,有关于使用DT with Shiny 的精彩文档。然后,一旦被选中,您就可以过滤客户表并使用 updateTabsetPanel 将用户发送到另一个选项卡。
下面是一个例子。
library(DT)
library(shiny)
df <- data.frame(
customer = LETTERS[1:5],
id = seq(1, 5)
)
ui <- navbarPage(
"Stackoverflow",
id = "tabs", # give id to use updateTabsetPanel
tabPanel(
"shop",
h2("Customers are below"),
DTOutput("table")
),
tabPanel(
"customer",
uiOutput("customer")
)
)
server <- function(input, output, session){
output$table <- renderDT(df, selection = "single")
observeEvent(input$table_rows_selected, {
updateTabsetPanel(session = session, inputId = "tabs", selected = "customer")
})
output$customer <- renderUI({
c <- df[input$table_rows_selected, "customer"]
h2(paste("Hi I'm customer", c, "!"))
})
}
shinyApp(ui, server)