Setting up a permalink style system in shiny

Hi,

I was hoping to set up a system a 'permalink' (for lack of a better description, not quite correct as 'permanency' isn't the goal) where a shiny app could be accessed via a url with a set of arguments that specify the start conditions, ie when the link is clicked a specific set of data/tabs is display at the start.
The functionality should be as normal from then on (ie I am not trying to restrict access) but the person would be placed into the app under specific conditions. The use case would be to allow a preformatted link to be sent to someone to access a specific set of data rather than saying, 'click here, select this etc'.

I have had a bit of a look around and can't see an easy way to do this, maybe I am just not thinking about the problem correctly, so thought I would ask if there was an existing condition or if anyone else had any bright ideas. It feels on the surface like a pretty standard requirement/request so I wonder if i am just approching the idea incorrectly.

Regards,
Josh

There are some pretty standard functions available in shiny regarding your request please see:

?parseQueryString()
?getQueryString()
?updateQueryString()

Here is an example:

library(DT)
library(shiny)
library(datasets)

ui <- fluidPage(
  DTOutput("mytable")  
)

server <- function(input, output, session) {  
  tabledata <- reactive({
    query_string <- getQueryString()
    if(is.null(query_string$tab)){
      data.frame(`Please visit` = c("http://127.0.0.1:80/?tab=iris", "http://127.0.0.1:80/?tab=mtcars"))
    } else if(query_string$tab == "iris"){
      # visit http://127.0.0.1:80/?tab=iris
      iris
    } else if (query_string$tab == "mtcars"){
      # visit http://127.0.0.1:80/?tab=mtcars
      mtcars
    } else {
      data.frame(x = "There is nothing here")
    }
  })
  
  output$mytable <- renderDT({
    tabledata()
  }, selection = "none")
}

app <- shinyApp(ui, server)

runApp(app, port = 80L, host = "0.0.0.0")

Furthermore please check my answers here or here.

Hi,

Thanks a lot for that, exactly the sort of thing I had in mind, an implementation of that should work well.

Really appreciate you taking the time to reply and the demo code is extremely helpful,

Thanks again,
Josh

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.