【问题标题】:Render output of print(data.tree) to the UI in shiny以闪亮的方式将 print(data.tree) 的输出渲染到 UI
【发布时间】:2018-02-09 00:29:22
【问题描述】:

我在控制台中输出 data.tree 包如下:

print(acme, "cost", "p")

#Out of Data.tree print JPEG

我想在闪亮的 UI 中呈现相同的输出结构。

我试过 paste(console.output(print(acme, "cost", "p")),collapse = "
"),但是输出结构不一样。

ui <- fluidPage(
          sliderInput(inputId = "slider", 
          label = "My number", 
          min = 300, 
          max = 19000,
          value = 5000),
          htmlOutput("mytext")
                   )

server <- function(input, output) {
          output$mytext <- renderText({
          paste(capture.output(print(acme, "cost", "p")),collapse = "<br/>")
       })
       }

shinyApp(ui = ui, server = server)

请向我推荐任何渲染函数,它们将在 Shiny UI 中打印与上面完全相同的输出。

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    TL:DR;在服务器中将renderText() 替换为renderPrint(),在ui 中将htmlOutput() 替换为verbatimTextOutput()

    问题在于renderText() 的工作方式。它将所有文本输入与cat() 连接起来,当对 data.tree 对象使用时,这将失败,这是一个列表。您应该使用renderPrint() 来捕获您的打印语句的输出。不需要capture.output()renderPrint() 不适用于各种输出方法,最安全的一种是verbatimTextOutput()。我基于实验而不是实际的文档研究来提出该建议。 htmlOutput 可能有效,但我不确定。

    更新代码:

    ui <- fluidPage(
              sliderInput(inputId = "slider", 
              label = "My number", 
              min = 300, 
              max = 19000,
              value = 5000),
              verbatimTextOutput("mytext")
                       )
    
    server <- function(input, output) {
              output$mytext <- renderPrint({
              print(acme, "cost", "p"))
           })
           }
    
    shinyApp(ui = ui, server = server)
    

    【讨论】:

      猜你喜欢
      • 2014-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-15
      • 2019-07-12
      • 1970-01-01
      • 2021-02-23
      相关资源
      最近更新 更多