我正在尝试使用cat
和\n
在一些文本输出中插入一些换行符shiny
。
这是我ui.R
和的相关部分server.R
。
假设我想获得t检验的结果,并为't','df'和'p-value'单独添加一行
我正在使用Shinydashboard布局。
Group_A <- 1:13
Group_B <- 8:19
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] 删除。
我来说两句