2

The HTML output is created by summarytool::dfSummary function.

summarytools

summarytools uses Bootstrap’s stylesheets to generate standalone HTML documents that can be displayed in a Web Browser or in RStudio’s Viewer using the generic print() function.

When the HTML gets rendered on the tabpanel, the whole UI changes. Is there a way to render the HTML on the tabpanel without changing the UI?

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)
Dominic Comtois
  • 10,230
  • 1
  • 39
  • 61
DRcod
  • 35
  • 7

1 Answers1

0

Version 0.8.3 of summarytools has a new boolean option, bootstrap.css which will prevent this from happening. Also, graph.magnif allows adjusting the graphs' size.

SumProfile <- print(dfSummary(recVal$dfdata), 
                    method = 'render',
                    omit.headings = TRUE,
                    footnote = NA,
                    bootstrap.css = FALSE,
                    graph.magnif = 0.8)

The latest version can be installed with devtools:

devtools::install_github("dcomtois/summarytools")

Good luck :)

Dominic Comtois
  • 10,230
  • 1
  • 39
  • 61