【问题标题】:navigating to specific tab from external link shiny从外部链接闪亮导航到特定选项卡
【发布时间】:2018-10-06 13:29:05
【问题描述】:

我正在尝试将我闪亮仪表板的特定视图的访问权限授予外部应用程序。基本上,我想给他们一个带有过滤器参数的 url 链接,这样当他们点击链接时,我闪亮的仪表板就会在应用了过滤器的特定视图上打开。我在SO上遇到了一些关于相同的其他帖子 Externally link to specific tabPanel in Shiny App

我尝试使用代码找出解决方案,但未能解决。这是我目前拥有的,我想要的是 http://127.0.0.1:7687/?url=%22Plot%202%22&species=%22setosa%22

这应该会打开仪表板的 Plot 2 选项卡并应用相关过滤器。对此的任何帮助都会很棒。谢谢!

library(shiny)
library(DT)


# Define UI for application that draws a histogram
ui <- navbarPage(title = "Navigate", id = 'nav',

   # Application title
   tabPanel("Plot",
            plotOutput("distPlot")
            ),
   tabPanel("Plot 2",
            selectInput("species", "Select Species", choices = c("setosa", "virginica"),
                        multiple = T, selected = NULL),
            dataTableOutput("tbl1")
            )
)

# Define server logic required to draw a histogram
server <- function(input, output, session) {

  observe({
    query <- parseQueryString(session$clientData$url_search)
    if(!is.null(query$url)) {
      url <- strsplit(query$url,"/")[[1]]
      updateTabsetPanel(session, 'nav', url)
    }
  })

   output$distPlot <- renderPlot({
      hist(rnorm(100), col = 'darkgray', border = 'white')
   })

   output$tbl1 <- renderDataTable({
     tmp <- iris
     if(!is.null(input$species))
        tmp <- iris[which(iris$Species %in% input$species), ]

     datatable(tmp)
   })
}

# Run the application
shinyApp(ui = ui, server = server)

【问题讨论】:

    标签: r shiny tabpanel


    【解决方案1】:

    你的观察应该如下:

      observe({
        query <- parseQueryString(session$clientData$url_search)
        if(!is.null(query$url)) {
          url <- strsplit(query$url,"\"")[[1]][2]
          species <- strsplit(query$species, "\"")[[1]][2]
          updateTabsetPanel(session, 'nav', url)
          updateSelectInput(session, 'species',selected = species)
        }
      })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-05
      • 2017-12-25
      • 1970-01-01
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多