【问题标题】:trigger an update of selectInput based on link selection from observeEvent in R Shiny根据 R Shiny 中的 observeEvent 的链接选择触发 selectInput 的更新
【发布时间】:2021-11-26 02:12:47
【问题描述】:

我想根据从 valueBox 文本中选择的链接动态更改 selectInput pdf 文件。

在原始代码中,在单独选项卡的 valueBoxes 中找到的 link1 和 link2 导航到带有 pdf 查看器和可用选项中的第一个 pdf 的公共选项卡面板。到目前为止,导航到公共选项卡面板有效,但我还希望事件根据 valueBox 选择更改 pdf 文件。

简化版(不带导航)如下:

shinyServer(function(input, output, session){

observeEvent(input$link1, {
updateSelectInput(session, inputId = "pdf_selection"
, choices = c("pdf1" = "location/pdf1.pdf"
, "pdf2" = "location/pdf2.pdf")
, selected = "pdf1")
})
observeEvent(input$link2, {
updateSelectInput(session, inputId = "pdf_selection"
, choices = c("pdf1" = "location/pdf1.pdf"
, "pdf2" = "location/pdf2.pdf")
, selected = "pdf2")
})

output$pdfView <- renderUI({
tags$iframe(style = "height:800px;width:100%", src = input$pdf_selection)
})

output$stat1 <- renderValueBox({
valueBox(subtitle = "fact 1", value = actionLink(inputId = "link1", label = HTML("Some statistic to report1")))
})

output$stat2 <- renderValueBox({
valueBox(subtitle = "fact 2", value = actionLink(inputId = "link2", label = HTML("Some statistic to report2")))
})

})

shinyUI(fluidPage(
dashboardPage(dashboardBody(
useShinyjs()
# Row showing the linked valueBoxes
, fluidRow(valueBoxOutput("stat1"), valueBoxOutput("stat2"))

, selectInput(inputId = "pdf_selection"
, label = "select pdf"
, choices = c("pdf1" = "location/pdf1.pdf", "pdf2" = "location/pdf2.pdf")
, selected = "")

# For viewing the selected pdf file
, htmlOutput("pdfView")
)

)))

选择链接后,所选选项似乎没有任何更新。非常感谢任何帮助。

【问题讨论】:

    标签: r pdf shiny hyperlink reactive


    【解决方案1】:

    经过反复试验,问题似乎出在observeEvent 行。对于选定的选项,“选定”选项应该是定义的选项而不是标签。所以应该是”selected" = "location/pdf1.pdf",而不是selected = "pdf1

    【讨论】:

      猜你喜欢
      • 2018-03-12
      • 2021-02-24
      • 2019-12-10
      • 1970-01-01
      • 2018-12-14
      • 2019-08-01
      • 2016-12-21
      • 1970-01-01
      • 2018-06-30
      相关资源
      最近更新 更多