在Shiny tabpanel上呈现HTML

时间:2018-02-26 00:16:14

标签: html r shiny

HTML输出由summarytool :: dfSummary函数创建。

summarytools

summarytools使用Bootstrap的样式表生成独立的HTML文档,可以使用通用的print()函数在Web浏览器或RStudio的Viewer中显示。

当HTML在tabpanel上呈现时,整个UI都会发生变化。有没有办法在不改变UI的情况下在tabpanel上呈现HTML?

library(summarytools)

ui <- fluidPage(
  titlePanel("dfSummary"),
  sidebarLayout(
    sidebarPanel(
      uiOutput("dfSummaryButton")
    ),
    mainPanel(
      tabsetPanel(
        tabPanel("Data Input",
         dataTableOutput("dataInput"),
         br(),
         verbatimTextOutput("profileSTR")),
        tabPanel("dfSummary Output",
         htmlOutput("profileSummary")))
    )
  )
)
server <- function(input, output, session) {
#Read in data file
recVal <- reactiveValues()
dfdata <- iris

#First 10 records of input file
output$dataInput <- renderDataTable(head(dfdata, n = 10), options = list(scrollY = '500px', 
                          scrollX = TRUE, searching = FALSE, paging = FALSE, info = FALSE, 
                          ordering = FALSE, columnDefs = list(list(className = 'dt-center', 
                          targets = '_all'))))

#str() of input file
output$profileSTR <- renderPrint({
  ProStr <- str(dfdata)
  return(ProStr) 
})

#Create dfSummary Button
output$dfSummaryButton <- renderUI({
      actionButton("dfsummarybutton", "Create dfSummary")
    })

### Apply dfSummary Buttom
observeEvent(input$dfsummarybutton, {
  recVal$dfdata <- dfdata
})

#dfSummary data
output$profileSummary <- renderUI({
       req(recVal$dfdata)
       SumProfile <- print(dfSummary(recVal$dfdata), omit.headings = TRUE, method = 'render')
       SumProfile
})
}
shinyApp(ui, server)

1 个答案:

答案 0 :(得分:0)

摘要工具的0.8.3版有一个新的布尔选项,axis(1, at = time(x.t)) 可以防止这种情况发生。此外,bootstrap.css允许调整图表&#39;大小

graph.magnif

可以使用SumProfile <- print(dfSummary(recVal$dfdata), method = 'render', omit.headings = TRUE, footnote = NA, bootstrap.css = FALSE, graph.magnif = 0.8) 安装最新版本:

devtools

祝你好运:)