【问题标题】:How to change the name of the choices in selectInput to avoid using URLs as the choice?如何更改 selectInput 中选项的名称以避免使用 URL 作为选项?
【发布时间】:2019-04-24 20:09:37
【问题描述】:

我正在尝试为我正在进行的项目创建仪表板。在这个项目中,我尝试使用renderUI 整合来自 tableau.public.com 的一些图。我希望仪表板使用selectInput 来选择要显示的画面图。我已经更改了下面的 URL,因此如果搜索它们将无法使用。

我当前的代码是:

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?

谢谢

【问题讨论】:

    标签: r shiny flexdashboard


    【解决方案1】:

    您可以定义一个包含绘图名称的向量和一个包含 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])
    })
    

    希望这会有所帮助。

    【讨论】:

    • 这正是我需要它做的。非常感谢!
    猜你喜欢
    • 2013-04-16
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    相关资源
    最近更新 更多