rstudio / shiny-examples

Other
1.97k stars 3.77k forks source link

navigating to specific tab from external link shiny #82

Closed mridulgarg11 closed 6 years ago

mridulgarg11 commented 6 years ago

Hi, I'm trying to give access to a specific view of my shiny dashboard to an external application. Basically, I want to give them a url link with a filter parameter so that when they click on the link, my shiny dashboard opens up on the specific view with the filters applied. I came across some other posts regarding the same on SO - https://stackoverflow.com/questions/33021757/externally-link-to-specific-tabpanel-in-shiny-app

I tried using the code to figure out the solution, but haven't been able to. This is what I currently have, what I'd like to have is something like http://127.0.0.1:7687/?url=%22Plot%202%22&species=%22setosa%22

This should open up the Plot 2 tab of the dashboard and apply the relevant filters. Any help on this would be great. Thanks!

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)](`url`)
wch commented 6 years ago

Hi, this issue tracker is for bug reports and feature requests for the shiny-examples repository. For general help questions like this, please use https://community.rstudio.com or https://stackoverflow.com.