download - Archive button in R shiny, activate only once -
i have following code runs perfectly!. however, want restrict archiving of data pushing "export all" button once per day. tried use if statements , not successful. fact code running on shiny-server pro , different browser sessions created. suggestions?.
library(shiny) library(shinybs) library(xlconnect) library(lubridate) cdata <- ' candidate,party,province,age,gender "l, l",ndp,quebec,22,female "m, m",bloc quebecois,quebec,43,female "m, s",bloc quebecois,quebec,34,female "s, d",ndp,quebec,,female "s, l",ndp,quebec,72,female "f, h",liberal,british columbia,71,female "t, n",ndp,quebec,70,female "s, j",liberal,ontario,68,female "r, francine",ndp,quebec,67,female "d, patricia",conservative,ontario,66,female "s, joy",conservative,manitoba,65,female "w, alice",conservative,british columbia,64,female "o, tilly",conservative,new brunswick,63,female "a, diane",conservative,alberta,63,female "d, linda",ndp,alberta,63,female "b, carolyn",liberal,ontario,62,female "n, peggy",ndp,ontario,61,female "m, irene",ndp,ontario,61,female "s, jinny",ndp,british columbia,60,female "f, judy",liberal,newfoundland,60,female "c, jean",ndp,british columbia,60,female "d, libby",ndp,british columbia,59,female "y, lynne",conservative,saskatchewan,59,female "d, anne",ndp,quebec,58,female "m, elizabeth",green,british columbia,58,female "m, joyce",liberal,british columbia,58,female "f, kerry",conservative,british columbia,57,female "b, lois",conservative,ontario,57,female "b, marj",ndp,quebec,57,female "c, joan",conservative,alberta,56,female "c, olivia",ndp,ontario,55,female "m, cathy",conservative,british columbia,55,female "f, diane",conservative,ontario,55,female "l, helene",ndp,quebec,54,female "g, nina",conservative,british columbia,54,female "h, carol",ndp,ontario,54,female "p, gail",conservative,prince edward island,53,female "t, susan",conservative,ontario,53,female "y, wai",conservative,british columbia,52,female' con <- textconnection(cdata) cel <- read.csv(con, header=true, stringsasfactors = false) cel$votes <- round(runif(nrow(cel), min=500, max=15000)) thedatadf <- cel ui <- fluidpage( titlepanel("archive data post on stack overflow"), # button , alert, use alert control onetime archive sidebarlayout( sidebarpanel( bsalert("alert"), downloadbutton("archivebtn", "archive all") ), # show table mainpanel( dt::datatableoutput('thedata') ) ) ) server <- function(input, output,session) { output$thedata <- dt::renderdatatable(dt::datatable(thedatadf,options = list(pagelength = 25,scrollx = true), rownames = false,class = 'cell-border stripe') %>% formatstyle(c(2:ncol(thedatadf)), color = styleinterval(55, c('red', 'black')))) output$archivebtn <- downloadhandler( filename = function() { paste("archivedata-", ymd(sys.date()), ".xlsx", sep="") }, content = function(file) { fname <- paste(file,"xlsx",sep=".") wb <- loadworkbook(fname, create = true) #creating sheets within excel workbook createsheet(wb, name = "the arc data") #writing sheet within excel workbook : writeworksheet(wb, thedatadf, sheet = "the arc data", startrow = 1, startcol = 1) saveworkbook(wb) file.rename(fname,file) # create message complition of archive createalert(session, "alert", "examplealert", style="success",title = "archive complete!", content = "data archived", append = false) } ) } # run application shinyapp(ui = ui, server = server)
Comments
Post a Comment