R shiny summary_table out 不在 html 中呈现
R shiny summary_table out does not render in html
我有一个简单的应用程序来计算摘要,摘要部分工作正常。我怎么想将结果输出回 UI 作为 html。我无法让它与 renderUI 和 html 输出一起工作。如果我使用 rendertable 和 tableoutput,我得到的部分输出缺少 headers 并且 html 表未解析。有什么指点吗?
library(qwraps2) #for the summary table
library(shiny)
library(dplyr)
ui <- fluidPage( tabsetPanel(
tabPanel("Summary",
# mainPanel(tableOutput('summarytab'))
mainPanel(htmlOutput('summarytab'))
)
)
)
server <- function(input, output){
output$summarytab <- renderUI({
our_summary1 <-
list("Miles per gallon" =
list("min" = ~ min(mpg),
"max" = ~ max(mpg),
"mean (sd)" = ~ qwraps2::mean_sd(mpg)),
"Cylinder" =
list("min" = ~ min(cyl),
"max" = ~ max(cyl),
"mean (sd)" = ~ qwraps2::mean_sd(cyl))
)
summary_table(filter(mtcars),our_summary1)
})
}
shinyApp(ui = ui, server = server)
哇,好难啊。这是我找到的解决方案。
library(qwraps2)
options(qwraps2_markup = "markdown")
library(shiny)
library(dplyr)
library(knitr) # for knit2html
ui <- fluidPage( tabsetPanel(
tabPanel("Summary",
# mainPanel(tableOutput('summarytab'))
mainPanel(uiOutput('summarytab'))
)
)
)
server <- function(input, output){
output$summarytab <- renderUI({
our_summary1 <-
list("Miles per gallon" =
list("min" = ~ min(mpg),
"max" = ~ max(mpg),
"mean (sd)" = ~ qwraps2::mean_sd(mpg)),
"Cylinder" =
list("min" = ~ min(cyl),
"max" = ~ max(cyl),
"mean (sd)" = ~ qwraps2::mean_sd(cyl))
)
stable <- summary_table(filter(mtcars),our_summary1)
HTML(knit2html(text=capture.output(stable), fragment.only=TRUE))
# do not forget 'capture.output'
})
}
shinyApp(ui = ui, server = server)
效果图不错:
PS: 看起来有 another possible rendering。但是我不知道怎么做,不知道用shiny能不能实现。
我有一个简单的应用程序来计算摘要,摘要部分工作正常。我怎么想将结果输出回 UI 作为 html。我无法让它与 renderUI 和 html 输出一起工作。如果我使用 rendertable 和 tableoutput,我得到的部分输出缺少 headers 并且 html 表未解析。有什么指点吗?
library(qwraps2) #for the summary table
library(shiny)
library(dplyr)
ui <- fluidPage( tabsetPanel(
tabPanel("Summary",
# mainPanel(tableOutput('summarytab'))
mainPanel(htmlOutput('summarytab'))
)
)
)
server <- function(input, output){
output$summarytab <- renderUI({
our_summary1 <-
list("Miles per gallon" =
list("min" = ~ min(mpg),
"max" = ~ max(mpg),
"mean (sd)" = ~ qwraps2::mean_sd(mpg)),
"Cylinder" =
list("min" = ~ min(cyl),
"max" = ~ max(cyl),
"mean (sd)" = ~ qwraps2::mean_sd(cyl))
)
summary_table(filter(mtcars),our_summary1)
})
}
shinyApp(ui = ui, server = server)
哇,好难啊。这是我找到的解决方案。
library(qwraps2)
options(qwraps2_markup = "markdown")
library(shiny)
library(dplyr)
library(knitr) # for knit2html
ui <- fluidPage( tabsetPanel(
tabPanel("Summary",
# mainPanel(tableOutput('summarytab'))
mainPanel(uiOutput('summarytab'))
)
)
)
server <- function(input, output){
output$summarytab <- renderUI({
our_summary1 <-
list("Miles per gallon" =
list("min" = ~ min(mpg),
"max" = ~ max(mpg),
"mean (sd)" = ~ qwraps2::mean_sd(mpg)),
"Cylinder" =
list("min" = ~ min(cyl),
"max" = ~ max(cyl),
"mean (sd)" = ~ qwraps2::mean_sd(cyl))
)
stable <- summary_table(filter(mtcars),our_summary1)
HTML(knit2html(text=capture.output(stable), fragment.only=TRUE))
# do not forget 'capture.output'
})
}
shinyApp(ui = ui, server = server)
效果图不错:
PS: 看起来有 another possible rendering。但是我不知道怎么做,不知道用shiny能不能实现。