I experienced the following behavior of Shiny dashboard: If I click on the download button to download a csv using a dashboard UI I always get the HTML of the UI downloaded. The same server-code using the standard fluidPage UI works nicely.
Here the code with dashboard:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(skin=c("red"),
dashboardHeader(title=h4("Machine Learning"), titleWidth = 350),
dashboardSidebar(
tabsetPanel(id= "tsp",
type = "tabs",
downloadButton("downloadData", "Download")
)
),#
dashboardBody( )
)
server <- function(input, output) {
output$downloadData <- downloadHandler(
filename = function() {
paste("TrueCorrelation", Sys.Date(),".csv", sep = "")
},
content = function(file) { write.csv(mtcars, file, row.names = FALSE) }
)
}
# Run the application
shinyApp(ui = ui, server = server)
and here with fluidPage:
library(shiny)
ui <- fluidPage(
titlePanel("Downloading Data"),
sidebarLayout(
sidebarPanel(downloadButton("downloadData", "Download")
),
mainPanel(
tableOutput("table")
)))
server <- function(input, output) {
output$downloadData <- downloadHandler(
filename = function() {
paste("TrueCorrelation", Sys.Date(),".csv", sep = "")
},
content = function(file) { write.csv(mtcars, file, row.names = FALSE) }
)
}
shinyApp(ui = ui, server = server)
Is there a possibility to overcome this, as I prefer the dashboard UI? Thank you very much for your help