r - 由 selectInput 选择的内容的 shinyapps.IO 自定义 URL
问题描述
我想在 shinyapps.IO 中生成一个自定义 URL(或愿意升级到适当的企业工具),基于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)
我在https://community.rstudio.com/t/vanity-urls-with-connect-via-deployapp/18927/4阅读了有关“虚荣 URL”的信息,但这似乎不太像我正在寻找的解决方案.
感谢您的任何建议。
解决方案
就像我在评论中提到的那样,我认为您正在寻找书签,请参阅?shiny::enableBookmarking()
。
对于书签,您必须对代码进行三处修改。制作
ui代码一个函数
ui <- function(request){...}
在您的用户界面中包含一个书签触发器/按钮
bookmarkButton()
在启动应用程序之前启用书签。
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)
推荐阅读
- shell - 脚本完成时防止 tmux 退出
- python - 如何基于另一列将数据附加到数据框?
- c# - 从 Visual C# 2019 创建的 DLL 可以在 MFC 6.0 中使用吗?
- svn - 将分支转换为标签 svn?
- css - 导航菜单的字体粗细在内部页面上看起来不同 - WordPress
- firebase - NextJS firebase 模拟器功能不断编译、删除和重建 next.js 服务器,直到发生超时
- gimp - Gimp Python 脚本单独工作,但组合时不工作
- android - 编辑 framework-res apk 以更改通知阴影覆盖颜色
- python - 使用多列调用 set_index 时,datetime.date 值将转换为 pd.tslib.Timestamps
- oracle - 从 APEX_WORKSPACE_APEX_USERS 获取用户凭证以用于 oracle apex 中的 TFA