使用Cat将换行符插入文本输出中

牙买加的

我正在尝试使用cat\n在一些文本输出中插入一些换行符shiny

这是我ui.R的相关部分server.R

假设我想获得t检验的结果,并为't','df'和'p-value'单独添加一行

我正在使用Shinydashboard布局。

样本数据

Group_A <- 1:13
Group_B <- 8:19

ui

box(title = "T-test results:", status = "primary",  textOutput("text3"), width=3)

服务器

output$text3 <- renderPrint({

  obj <-  t.test(Group_A, Group_B)

  cat("t = ", round(obj[[3]],3), "\n, df = ", round(obj[[2]],3), "\n, p-value = ", round(obj[[3]],5)) 

})

下图显示了此输出:

在此处输入图片说明

如您所见,输出在屏幕上从左到右以逗号分隔。因为我要添加许多结果,所以我希望它们在屏幕上自上而下在每个值之后加一个换行符。

有谁知道该怎么做shiny

裁员

这是使用renderUI的解决方案htmlOutput

library(shiny)
Group_A <- 1:13
Group_B <- 8:19

runApp(
  list(
    ui = fluidPage(
      htmlOutput("text3")
      ),
    server = function(input, output){
      output$text3 <- renderUI({

        obj <-  t.test(Group_A, Group_B)
        HTML(
          paste0("t = ", round(obj[[3]],3), '<br/>', 
              "df = ", round(obj[[2]],3), '<br/>',
              "p-value = ", round(obj[[3]],5))
        )
      })
    }))

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章