Shiny - 通过appendTab()创建的书签标签

时间:2017-11-13 15:30:06

标签: r shiny shinydashboard

我正在我的应用中实施向下钻取,以便当用户点击数据表时,会打开新标签,显示所选单元格的详细信息。我想在我的应用程序中添加自动书签(url更新),以便我可以发送指向新生成的特定选项卡的链接,但该选项卡未正确恢复。我认为在恢复过程中不会触发观察者。关于如何使其发挥作用的任何想法?

最小例子:

library(shiny)
library(DT)
library(shinydashboard)

ui <- function(request) {
    dashboardPage(
        dashboardHeader(title = "Drilldown not restoring"),
        dashboardSidebar(disable = T),
        dashboardBody(
            tabsetPanel(id = "tabs",
                        tabPanel("Cars overview",
                                 h1("Cars overview"),
                                 div("Click any cell"),
                                 br(),
                                 DT::dataTableOutput("mtcars")
                        )
            )
        )
    )
}

server <- function(input, output, session) {

    # Generate data table
    output$mtcars <- DT::renderDataTable({mtcars})

    # Observe when row is selected and open new tab
    observeEvent(input$mtcars_rows_selected, {
        print("Trigger")
        appendTab(inputId = "tabs",
                  tabPanel(
                      "Car details",
                      "Car detail info"

                  )
        )
        # Focus on newly created tab
        updateTabsetPanel(session, "tabs", selected = "Car details")
    })

    # Enable bookmarking
    observe({
        reactiveValuesToList(input)
        session$doBookmark()
    })
    onBookmarked(function(url) {
        updateQueryString(url)
    })
}

shinyApp(ui, server, enableBookmarking = "url")

0 个答案:

没有答案