R Shiny 下载处理程序无法读取服务器中的其他输出

R Shiny Download Handler Cant Read in other Output in the Server

我正在尝试在我的 R Shiny 应用程序中使用 downloadHandler 函数,但遇到错误。

我的相关位 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)
  }
)

})

我的ui.R的相关位:

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

我收到以下错误:

could not find function "week1day1"

非常感谢您的帮助或任何正确方向的指示!

您的 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 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()
  }
)

})