闪亮 - 多个输出到mainPanel

时间:2014-12-09 15:36:15

标签: r shiny

Shiny似乎只接受mainPanel中提供给ui.R的任何内容的最终输出。 earlier SO question提出了这一点,但没有达到令人满意的解决方案。 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?")
  })
)

有谁知道这是一个错误,还是如何解决它?

1 个答案:

答案 0 :(得分:4)

尝试

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