1

I would like to have a custom URL generated in shinyapps.IO (or willing to upgrade to appropriate Enterprise tools) based on value selected by selectInput(). In the example below, if I publish to shinyapps.IO, the URL will be https://myDomain.shinyapps.io/myAppName/.

I would like 5 unique URLs, based on the user-selected option from selectInput().

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(tidyverse)

#################### UI   ###################
ui <- dashboardPagePlus(
  ###### Header ####
  
  header = dashboardHeaderPlus(
    title = NULL,
    titleWidth = '250',
    disable = FALSE,
    enable_rightsidebar = FALSE,
    .list = NULL,
    left_menu = tagList(
      selectInput(
        inputId = "options",
        label = "Select an option",
        choices = c('Option1', 'Option2', 'Option3', 'Option4', 'Option5'))
    ) #end left_menu
  ), #close Header
  
  
  ###### Sidebar ####
  sidebar = dashboardSidebar(disable = TRUE),
  
  footer = dashboardFooter(NULL),
  ###### Body ####
  body = dashboardBody(
    uiOutput('optionSelected')
  ) #close dashboardBody
) # closes Dashboard Page Plus

#################### SERVER   #################### 
server = function(input, output, session) { 
 
  output$optionSelected <- renderUI({
    input$options
  }
  )
}

shinyApp(ui = ui, server = server)

I have read about 'Vanity URLs' at https://community.rstudio.com/t/vanity-urls-with-connect-via-deployapp/18927/4, but this does not quite seem like the solution that I am seeking.

Thank for any advice.

3

1 Answer 1

2
+200

Like i mentioned in the comment, i think you are looking for bookmarking, see ?shiny::enableBookmarking().

For bookmarking you have to make three modifications to your code. Make

  1. the ui code a function

    ui <- function(request){...}
    
  2. include a bookmark trigger/button in your ui

    bookmarkButton()
    
  3. Enable bookmarking before you launch the app.

    enableBookmarking("url")
    

Minimal reproducible example would be:

ui <- function(request) {
  fluidPage(
    selectInput("options", "opt", choices = c('Option1', 'Option2')),
    bookmarkButton()
  )
}
server <- function(input, output, session) { }
enableBookmarking("url")
shinyApp(ui, server)

Automating the generation of urls

port_nr <- 3033
input_id <- "select_opt"
choices <- c('Option1', 'Option2')
paste0("http://127.0.0.1:", port_nr, "/?_inputs_&", input_id, "=", 
   URLencode(choices, reserved = TRUE))

Your example would read:

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

ui <- function(request) {
    dashboardPagePlus(
    ###### Header ####
    
    header = dashboardHeaderPlus(
      title = NULL,
      titleWidth = '250',
      disable = FALSE,
      enable_rightsidebar = FALSE,
      .list = NULL,
      left_menu = tagList(
        selectInput(
          inputId = "options",
          label = "Select an option",
          choices = c('Option1', 'Option2', 'Option3', 'Option4', 'Option5'))
      ) #end left_menu
    ), #close Header
    
    
    ###### Sidebar ####
    sidebar = dashboardSidebar(disable = TRUE),
    
    footer = dashboardFooter(NULL),
    ###### Body ####
    body = dashboardBody(
      uiOutput('optionSelected'),
      bookmarkButton()
    ) #close dashboardBody
  ) # closes Dashboard Page Plus
}
#################### SERVER   #################### 
server = function(input, output, session) { 
  
  output$optionSelected <- renderUI({
    input$options
  }
  )
}
enableBookmarking("url")
shinyApp(ui = ui, server = server)
2
  • Thank you! I was looking for something a bit more automated, but I appreciate your efforts and can use this idea as a workaround. Thanks again for your time and talent! Mar 29, 2021 at 17:33
  • 1
    understood! See my edit, section 'Automating the generation of urls'. Mar 29, 2021 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.