R Don';I don’我不知道如何设置反应性值

R Don';I don’我不知道如何设置反应性值,r,shiny,R,Shiny,我正在尝试构建一个闪亮的应用程序,它接受许多参数(实验次数、交叉验证的折叠次数和输入数据文件),然后在后台运行一些.R脚本。但我一直得到以下错误: “如果没有活动-反应上下文,则不允许操作。(您试图执行的操作只能从反应函数内部执行。)” 下面是my ui.R的代码片段: library(shiny) experiments <- list( "1" = 1, "3" = 3, "5" = 5, "10" = 10, "50" = 50 ) folds <- li

我正在尝试构建一个闪亮的应用程序,它接受许多参数(实验次数、交叉验证的折叠次数和输入数据文件),然后在后台运行一些.R脚本。但我一直得到以下错误:

“如果没有活动-反应上下文,则不允许操作。(您试图执行的操作只能从反应函数内部执行。)”

下面是my ui.R的代码片段:

library(shiny)

experiments <- list(
  "1" = 1,
  "3" = 3,
  "5" = 5,
  "10" = 10,
  "50" = 50
)
folds <- list(
  "1" = 1,
  "3" = 3,
  "5" = 5,
  "10" = 10
)

shinyUI(
  pageWithSidebar(
    headerPanel("Classification and Regression Models"),
    sidebarPanel(
      selectInput("experiments_number", "Choose Number of Experiments:",
                  choices = experiments)
      selectInput("folds_number", "Choose Number of Folds:", choices = folds),
      fileInput(
        "file1",
        "Choose a CSV file:",
        accept = c('text/csv', 'text/comma-separated-values', 'text/plain')
      )
    ),
库(闪亮)

实验在你的CART.R中,你有一行
数据集,我想如果不看什么是CART.R,我们什么都说不出来。好的,我已经把输入包装成了反应函数。但是在server.R或CART.R中,我在哪里以及如何调用ds()-呢?反应式函数将从shinyServer内部的server.R中调用。首先,我建议将CART.R中的所有内容都放到server.R中。如果您真的需要,您可以稍后使用
source
。谢谢。您能给我举个例子吗?我一直在摆弄它,但无法让它工作(另外,我真的需要使用source()。。。
shinyServer(function(input,output){
    # Server logic goes here.

    experimentsInput <- reactive({
        switch(input$experiments_number,
            "1" = 1,
            "3" = 3,
            "5" = 5,
            "10" = 10,
            "50" = 50)
    })

foldsInput <- reactive({
        switch(input$folds_input,
            "1" = 1,
            "3" = 3,
            "5" = 5,
            "10" = 10)
    })

if (is.null(input$file1$datapath))
                return(NULL)

source("CART.R")
ds <- reactive({
  dataset <- input$file1$datapath
})
source("CART.R") #which does NOT access reactive elements
#common functions go here. (non-reactive ones)

shinyServer(function(input, output) { 
  
  ds <- reactive({
    dataset <- input$file1$datapath
  })
         
  output$rt <- renderText({
    {  ds1 <- ds()
      #now ds1 is available in this function
      Do something with ds1
    }
  })