我一直在尝试运行这个简单的闪亮应用程序。它抛出以下错误
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.)
以下是我写的代码
用户界面
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)
有人可以在这里帮助我。我查看了一些与此类似的线程。似乎没有任何帮助。