【问题标题】:Shiny dashboard reactive table with links带有链接的闪亮仪表板反应表
【发布时间】:2019-02-24 16:31:21
【问题描述】:

我在闪亮仪表板中的一个标签(我们称之为商店标签)中有一张客户表。我想为每个客户添加链接,这些链接会将您发送到闪亮仪表板(客户选项卡)中的另一个选项卡,该选项卡将提供有关该特定客户的更详细信息(主要是客户行为图表)。这可以通过复制客户 ID 并将其粘贴到客户选项卡中的搜索栏中轻松实现,但我想知道是否可以更交互地执行此操作 -> 通过单击商店选项卡中的特定客户,仪表板发送您到客户选项卡,同时将客户 ID 填写到搜索栏中,因此您将获得所有按客户 ID 过滤的图表。 欢迎所有建议。

谢谢!

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    您可以使用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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-17
      • 2015-04-22
      • 2019-05-20
      • 2020-06-10
      • 1970-01-01
      • 1970-01-01
      • 2019-02-12
      • 2021-04-11
      相关资源
      最近更新 更多