R Shiny Download Handler Cant Read in other Output in the Server -
i trying use downloadhandler function in r shiny app , encounter erorr.
relevant bit of server.r:
shinyserver(function(input, output, process) { output$week1day1<-dt::renderdatatable({ bench <- input$bench.input squat <- input$squat.input dl <- input$dl.input ex1 <- input$day1main ex2 <- input$day1acc1 ex3 <- input$day1acc2 ex4 <- input$day1ass1 ex5 <- input$day1ass2 pr1 <- input$week1day1ex1pr/100 pr2 <- input$week1day1ex2pr/100 pr3 <- input$week1day1ex3pr/100 w4 <- input$week1day1ex4pr w5 <- input$week1day1ex5pr if(grepl("squat",ex1)){ w1 <- pr1*squat } if(grepl("bench",ex1)){ w1 <- pr1*bench } if(grepl("deadlift",ex1)){ w1 <- pr1*dl } ### if(grepl("squat",ex2)){ w2 <- pr2*squat } if(grepl("bench",ex2)){ w2 <- pr2*bench } if(grepl("deadlift",ex2)){ w2 <- pr2*dl } ### if(grepl("squat",ex3)){ w3 <- pr3*squat } if(grepl("bench",ex3)){ w3 <- pr3*bench } if(grepl("deadlift",ex3)){ w3 <- pr3*dl } table1<- data.frame(exercise=c(ex1,ex2,ex3,ex4,ex5), sets=sets.week1, reps=reps.week1.day1, weight=c(w1,w2,w3,w4,w5)) dt::datatable(table1,options = list(bfilter=0, bsort=0, bprocessing=0, bpaginate=0, binfo=0)) }) output$downloaddata <- downloadhandler( filename <- paste("program", '.csv', sep=''), content <- function(file) { write.csv(week1day1(), file) } ) })
the relevant bit of ui.r:
fluidrow(downloadbutton('downloaddata', 'download'))
i following error:
could not find function "week1day1"
i appreciate or pointers in right direction!
minimal working example of server.r:
shinyserver(function(input, output, process) { week1day1<- reactive({ bench <- input$bench.input squat <- input$squat.input dl <- input$dl.input ex1 <- input$day1main ex2 <- input$day1acc1 ex3 <- input$day1acc2 ex4 <- input$day1ass1 ex5 <- input$day1ass2 pr1 <- input$week1day1ex1pr/100 pr2 <- input$week1day1ex2pr/100 pr3 <- input$week1day1ex3pr/100 w4 <- input$week1day1ex4pr w5 <- input$week1day1ex5pr if(grepl("squat",ex1)){ w1 <- pr1*squat } if(grepl("bench",ex1)){ w1 <- pr1*bench } if(grepl("deadlift",ex1)){ w1 <- pr1*dl } ### if(grepl("squat",ex2)){ w2 <- pr2*squat } if(grepl("bench",ex2)){ w2 <- pr2*bench } if(grepl("deadlift",ex2)){ w2 <- pr2*dl } ### if(grepl("squat",ex3)){ w3 <- pr3*squat } if(grepl("bench",ex3)){ w3 <- pr3*bench } if(grepl("deadlift",ex3)){ w3 <- pr3*dl } table1<- data.frame(exercise=c(ex1,ex2,ex3,ex4,ex5), sets=sets.week1, reps=reps.week1.day1, weight=c(w1,w2,w3,w4,w5)) # delete these line , add options part @ end of renderdatatable below # dt::datatable(table1,options = list(bfilter=0, bsort=0, bprocessing=0, bpaginate=0, binfo=0)) }) output$week1day1display<-dt::renderdatatable({ return(week1day1()) }, options = list(bfilter=0, bsort=0, bprocessing=0, bpaginate=0, binfo=0)) # options added output$downloaddata <- downloadhandler( filename <- paste("program", '.csv', sep=''), content <- function(file) { write.csv(week1day1(), file) # here had week1day1display() instead of week1day1() } ) })
Comments
Post a Comment