我正在尝试构建一个 Shiny 应用程序,它接受许多参数(实验次数、交叉验证的折叠次数和输入数据文件),然后在后台运行一些 .R 脚本。但我不断收到以下错误:
“在没有主动反应上下文的情况下不允许操作。(你试图做一些只能从反应函数内部完成的事情。)”
这是我的 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')
)
),
以及我的 server.R 代码的开头:
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")
有任何想法吗?
谢谢!