R-反应性错误:警告:在.getReactiveEnvironment()$currentContext中出错

R-反应性错误:警告:在.getReactiveEnvironment()$currentContext中出错,r,shiny,reactive,R,Shiny,Reactive,我一直在尝试运行这个简单的闪亮应用程序。它抛出以下错误 Warning: Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.) Stack t

我一直在尝试运行这个简单的闪亮应用程序。它抛出以下错误

Warning: Error in .getReactiveEnvironment()$currentContext: Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.) Stack trace (innermost first):
    49: .getReactiveEnvironment()$currentContext
    48: .subset2(x, "impl")$get
    47: $.reactivevalues
    46: $ [#13]
    45: server [#13]
     4: <Anonymous>
     3: do.call
     2: print.shiny.appobj
     1: <Promise> Error in .getReactiveEnvironment()$currentContext() :    Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
警告:.getReactiveEnvironment()中出错$currentContext:如果没有活动的反应上下文,则不允许操作。(您试图执行的操作只能从反应式表达式或观察者内部执行。)堆栈跟踪(最内层优先):
49:.getReactiveEnvironment()$currentContext
48.。第2(x)子节,“impl”)$get
47:$.reactivevalues
46: $ [#13]
45:服务器[#13]
4: 
3:打电话
2:print.shinny.appobj
1:getReactiveEnvironment()$currentContext()中出错:如果没有活动的反应上下文,则不允许操作。(您试图做的事情只能从被动表达式或观察者内部完成。)
下面是我写的代码

用户界面
库(闪亮)

ui我无法运行您的代码。我得到一个错误:
警告:错误与您问题中的错误一致,我猜这是因为您在反应式表达式外部调用了
filedata()
。由于
filedata()
调用
input$file1
无法像正常函数一样使用它,因此只能从反应式表达式内部调用
filedata()
。我无法运行您的代码。我得到一个错误:
警告:错误与您问题中的错误一致,我猜这是因为您在反应式表达式外部调用了
filedata()
。由于
filedata()
调用
input$file1
无法像普通函数那样使用它,因此只能从反应式表达式内部调用
filedata()
library(shiny)

ui <- fluidPage(
  titlePanel("Uploading Files"),
  sidebarLayout(
    sidebarPanel(
      fileInput('datafile', 'Choose CSV file',
                accept=c('text/csv', 'text/comma-separated-values,text/plain')),
      tags$hr(),
      checkboxInput('header', 'Header', TRUE),
      radioButtons('sep', 'Separator',
                   c(Comma=',',
                     Semicolon=';',
                     Tab='\t'),
                   ','),
      radioButtons('quote', 'Quote',
                   c(None='',
                     'Double Quote'='"',
                     'Single Quote'="'"),
                   '"'),

      numericInput("num", "Path length", 2, min = 1, max = 100)

    ),
    mainPanel(
      tableOutput('contents')
    )
  )
)
# Server

server <- function(input, output) {


  # input$file1 will be NULL initially. After the user selects
  # and uploads a file, it will be a data frame with 'name',
  # 'size', 'type', and 'datapath' columns. The 'datapath'
  # column will contain the local filenames where the data can
  # be found.


  numConv <- reactive({as.numeric(input$num)})

  filedata <- reactive ({
    file_x <- input$file1
    if (is.null(file_x))
      return(NULL)
    read.csv(file_x$datapath)
  )}

  #naming the columns


  colnames(filedata()) <- c("id_user","datetime","site_domain")

  #sorting by time
  filedata() <- filedata()[order(file_x$datetime,decreasing = T),]

  #Removing timestamp column
  file_x1 <- file_x[-2]


  #Appendiing the site domains
  options(dplyr.width = Inf)

  #t <- gsub("^([^_]*_[^_]*)_.*$", "\\1", file_x2$pages)
  file_x2 <- file_x1 %>%
    group_by(id_user) %>%
    summarise(pages=paste(rle(as.character(site_domain))$values, collapse='_'))

  #
  # #selecting first n site domains
  file_x3 <- reactive ({file_x2 %>%
    group_by(id_user) %>% summarise(path=paste(strsplit(pages,"_")[[1]][1:input$numConv()],collapse="_"))
  })


  output$contents <- renderTable({
    file_x3()

  })
}

shinyApp(ui=ui,server=server)