This should do what you want...the trick is to converting the result of compare_df() to an htmlwidget, so that you can treat just like any other htmlwidget (i.e., use htmlwidgets::saveWidget() as well as shiny output/render helpers). IMO the compareDF package should make this easier...
library(shiny)
library(compareDF)
library(htmlTable)
ui <- fluidPage(
sidebarPanel(
downloadButton("Export_HTML", "Export as Data Listing")
),
# Main panel for displaying outputs ----
mainPanel(htmlTableWidgetOutput('diff_table'))
)
server <- function(input,output){
old_df <- data.frame(var1 = c("A", "B", "C"),
val1 = c(1, 2, 3))
new_df <- data.frame(var1 = c("A", "B", "C"),
val1 = c(1, 2, 4))
diff <- compare_df(new_df, old_df, c("var1"))
diff_widget <- htmlTableWidget(diff$html_output)
output$diff_table <- renderHtmlTableWidget({
diff_widget
})
output$Export_HTML <- downloadHandler(
filename = function() {
paste("Comparison-", Sys.Date(), ".html", sep = "")
},
content = function(file) {
saveWidget(diff_widget, file, selfcontained = TRUE)
}
)
}
shinyApp(ui, server)