在Shiny中如何将多个输出显示在主面板上?

4
Shiny似乎只接受在ui.R中提供给mainPanel的最终输出。一个早期的SO问题提出了这个问题,但没有得到令人满意的解决方案。 mainPanel的文档表明应该是可能的:

描述:创建包含输出元素的主面板

下面的代码说明了这一点: server.R
library(shiny)
shinyServer(
  function(input, output) {
    plotInput <- reactive({
      list(plot = plot(1:10),
        txt = "My reactive title")
    })
    output$myplot <- renderPlot({ plotInput()$plot })
    output$txt <- renderText({ plotInput()$txt })
  }
)

ui.R

require(shiny)
pageWithSidebar(
  headerPanel("Multiple outputs to mainPannel"),
  sidebarPanel(),
  mainPanel({
    # only the last output works
    h1(textOutput("txt"))
    plotOutput("myplot")
    p("see what I mean?")
  })
)

有人知道这是一个bug吗?还是有什么方法可以解决它?

1个回答

5

尝试

  mainPanel(
    # only the last output works
    h1(textOutput("txt")),
    plotOutput("myplot"),
    p("see what I mean?")
  )

4
别担心;令人讨厌的嵌套和令人困惑的错误信息使得在调试Shiny应用时充满了乐趣(即使它设计得非常巧妙)。 - Dieter Menne
谢谢。顺便问一下,您对使用plotInput()$plot方法从reactive()中提供多个输出有什么看法?如果有更好的方法,我很感兴趣听听。 - geotheory

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接