【问题标题】:Shiny - multiple outputs to mainPanelShiny - 多个输出到 mainPanel
【发布时间】:2014-12-09 15:36:14
【问题描述】:

Shiny 似乎只接受在ui.R 中提供给mainPanel 的任何最终输出。 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?")
  })
)

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

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    试试

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

    【讨论】:

    • 不要;令人讨厌的嵌套和令人困惑的错误消息使 Shiny 成为一次愉快的调试冒险(即使它设计巧妙)。
    • 谢谢。顺便说一句,您对plotInput()$plot 提供来自reactive() 的多个输出的方法有何评论?我很想知道是否有更好的方法..
    猜你喜欢
    • 2020-07-09
    • 2014-03-20
    • 2017-06-03
    • 2016-07-21
    • 2014-10-12
    • 2019-06-09
    • 2021-07-28
    • 2018-08-13
    • 2018-05-29
    相关资源
    最近更新 更多