R блестящий обработчик загрузки не может читать в других выходных данных на сервере

Я пытаюсь использовать функцию downloadHandler в моем приложении R Shiny и сталкиваюсь с erorr.

Соответствующий бит моего сервера.Р:

   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)
  }
)

})

Соответствующий бит моего пользовательского интерфейса.Р:

fluidRow(downloadButton('downloadData', 'Download'))

Я получаю следующую ошибку:

could not find function "week1day1"

Я был бы очень признателен за вашу помощь или любые указатели в правильном направлении!

1 ответ

  1. Минимальный рабочий пример вашего сервера.Р:

    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 and add the options part at the end of the 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 you had week1day1Display() instead of week1day1()
      }
    )
    
    })