我正在尝试访问外部应用程序的闪亮仪表板的特定视图。基本上,我想给他们一个带有过滤器参数的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)
答案 0 :(得分:2)
您的观察应如下:
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)
}
})