1

この単純な光沢のあるアプリケーションを実行しようとしています。次のエラーをスローしています

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

以下は私が書いたコードです

UI

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)

誰かがここで私を助けてくれますか。これに似たいくつかのスレッドを見ました。どれも役に立たないようです。

4

0 に答える 0