I want a user to download a file which is in tabular format with header along with two search widgets on top. The output is forecasted values along with 80%(High-low) and 95%(High-low) confidence interval.So there are five columns, five rows(default). However, i am having two challenges here.
Challenge 1: When I run the app, after clicking on "Download the file" filename is coming as download data with no extension whereas I have mentioned filename should be "forecasted" with png extension and it should come as forecated.png
Challenge 2: After typing png as extension while saving the file, the file is saved but nothing gets printed.
I have searched in various forums and try to replicate them but nothing seems to be working.
Please suggest.
shiny UI
library(shiny)
downloadButton(outputId = "downloaddata" ,label ="Download the file"),
shiny server
output$downloaddata<-downloadHandler(
filename = function(){
paste("forecasted","png",sep=",")
},
content = function(file){
png(file)
h <-input$fst
tab<-forecast(Model_mape(),h)
datatable(as.data.frame(tab), options = list(
columnDefs = list(list(targets = c(1, 3), searchable = FALSE)),
pageLength = 10))
dev.off()
}
)
Maybe it could help you (it's a simple instance):
Ui :
library(shiny)
shinyUI(fluidPage(
mainPanel(plotOutput("plot1"),
downloadButton("downloadplot","Download your plot"))
))
Server :
library(shiny)
shinyServer(function(input, output) {
your_plot = function(){
(plot(rnorm(1000,0,1)))
}
output$plot1 <- renderPlot({
your_plot()
})
output$downloadplot <- downloadHandler(
filename = "plot_exemple.png",
content = function(file) {
png(file, width = 1200, height = 800)
print(your_plot())
dev.off()
})
})
With this, you can easily download a png (open it in a browser).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.