r-shinyapps.通过选择Input选择的内容的IO自定义URL



我想在shinyapps中生成一个自定义URL。IO(或愿意升级到适当的企业工具(基于selectInput()选择的值。在下面的示例中,如果我发布到shinyapps。IO,URL将为https://myDomain.shinyapps.io/myAppName/.

我想要5个唯一的URL,基于用户从selectInput((中选择的选项。

  • https://myDomain.shinyapps.io/myAppName/Option1
  • https://myDomain.shinyapps.io/myAppName/Option2
  • https://myDomain.shinyapps.io/myAppName/Option3
  • https://myDomain.shinyapps.io/myAppName/Option4
  • https://myDomain.shinyapps.io/myAppName/Option5
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)

我在上读过关于"虚荣URL"的文章https://community.rstudio.com/t/vanity-urls-with-connect-via-deployapp/18927/4,但这似乎不是我正在寻求的解决方案。

谢谢你的建议。

正如我在评论中提到的,我认为您正在寻找书签,请参阅?shiny::enableBookmarking()

对于书签,您必须对代码进行三次修改。制作

  1. ui代码一个函数

    ui <- function(request){...}
    
  2. 在你的ui 中包含书签触发器/按钮

    bookmarkButton()
    
  3. 在启动应用程序之前启用书签。

    enableBookmarking("url")
    

最小可重复示例为:

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

自动生成url

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))

您的示例如下:

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)

相关内容

  • 没有找到相关文章

最新更新