如何更改 selectInput 中选项的名称以避免使用 URL 作为选项?

How to change the name of the choices in selectInput to avoid using URLs as the choice?

我正在尝试为我正在处理的项目创建仪表板。在这个项目中,我尝试使用 renderUI 整合 tableau.public.com 中的一些图。我希望仪表板使用 selectInput 到 select 将显示哪个画面图。我已经更改了下面的网址,因此如果搜索它们将无法使用。

我当前的代码是:

plot1<-"https://public.tableau.com/views/Sheet2?:showVizHome=no&:embed=true"
plot2<-"https://public.tableau.com/views/Sheet3?:showVizHome=no&:embed=true"

fluidPage(
  ##### Give a Title #####
  titlePanel("Tableau Visualizations"),

  ## Month Dropdown ##
  selectInput("URL", label = "Visualization:", 
              choices = c(plot1,plot2), selected = plot1))

以及显示 Tableau 页面的代码:

renderUI({
tags$iframe(style="height:600px; width:100%; scorlling=yes", src=input$URL)
})

除了 selectInput 选项外,代码执行我希望它执行的操作。我想让下拉菜单中的选项参考实际的地块名称(plot1plot2)。但是,由于它们是变量名,因此实际的下拉菜单中列出了 url。我不能使用以下内容,因为它不再将选择识别为变量:

  ## Month Dropdown ##
  selectInput("URL", label = "Visualization:", 
              choices = c("plot1,"plot2"), selected = plot1))

我是否可以显示变量的名称,但不能显示它们所代表的 url?

谢谢

您可以定义一个包含绘图名称的向量和一个包含 url 的命名向量,如下所示:

plot_names <- c("Plot1", "Plot2")
## Month Dropdown ##  
# Use the plot names here
selectInput("plot_name", label = "Visualization:", 
            choices = plot_names, selected = plot_names[1]))

然后显示网址:

urls <- c(Plot1 = "url1", Plot2 = "url2") # vector to get the urls from the names
renderUI({
tags$iframe(style="height:600px; width:100%; scorlling=yes", src=urls[input$plot_name])
})

希望对您有所帮助。