【发布时间】:2020-04-19 17:39:24
【问题描述】:
我见过很多关于将 .Rdata 文件上传到 R Shiny 的问题,但它们都包含某种输入对象。有没有办法在全局环境中上传它并在应用程序中使用它来创建新对象?不得不说这个 .Rdata 文件是另一个闪亮的应用程序的结果。 这是我尝试过的:
# --------------------------------------- Global --------------------------------------- #
# Set working directory -> Ctrl+Shift+H & Open the app folder
setwd("~/Programación en R/Shiny app/Final dashboard app")
# --------------------- Initialize program --------------------- #
# Print in console: global script is beginning to run
print("global.R")
# Allow specific errors to be displayed on screen, instead of displaying a generic error
options(shiny.sanitize.errors = FALSE)
# Load LDA model outcome, topic names & raw data
load("LDA_output.2019-12-28.RData")
#--------------------------------------- User Interface ---------------------------------------#
# Tell user ui script is beginning to run
print("ui.R")
ui <- fluidPage(
theme = shinytheme("cerulean"),
DT::dataTableOutput("lili")
) #fluidPage
#--------------------------------------- Server ---------------------------------------#
server <- function(input, output, session) {
mod <- reactive({get(load("LDA_output.2019-12-28.RData"))})
print(mod())
output$lili <- DT::renderDataTable({
DT::datatable(as.data.frame(mod()[[1]][3])) #list inside that list
})
}
shinyApp(ui, server)
这是由此产生的错误:
Listening on http://127.0.0.1:6282
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.)
58: stop
57: .getReactiveEnvironment()$currentContext
56: getCurrentContext
55: .dependents$register
54: mod
52: server [#4]
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.)
这是我最后使用的服务器功能,
server <- function(input, output, session) {
observe({
print(typeof(mod))})
output$lili <- DT::renderDataTable({
DT::datatable(as.data.frame(mod[[2]]))
})
}
shinyApp(ui, server)
但还是有问题:
Listening on http://127.0.0.1:6282
[1] "list"
Warning: Error in checkName: Must use single string to index into reactivevalues
[No stack trace available]
【问题讨论】:
标签: file-upload shiny shiny-server shinyapps