我想根据从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")
)
)))
链接被选中后,所选选项似乎没有任何更新。如有任何帮助,不胜感激。
经过一些尝试和错误,问题似乎来自observeEvent
行。对于选中的选项,"selected"&;选择应该是被定义的选择,而不是标签。所以不是selected = "pdf1
,应该是”selected" = "location/pdf1.pdf"
。