R 如何将读取为列表的输出对象转换为数据帧?

R 如何将读取为列表的输出对象转换为数据帧?,r,shiny,reactive-programming,reactive,typeof,R,Shiny,Reactive Programming,Reactive,Typeof,我正在尝试在R闪亮的应用程序之间进行一些交互。我从我的第一个应用程序中获得了第一个输出([1]列表、[2]data.frame&[3]data.frame)。我想用它在一个新的应用程序中应用新的功能,这个应用程序最终将成为我的最终仪表板。问题是,既然对象在全局环境中是非反应性的,它们都是列表类型,即使我使用as.data.frame函数(如下所示)。我不知道这是否是原因,但我只是发现它错了,在我的服务器功能中找不到它。知道为什么吗 # ------------------------------

我正在尝试在R闪亮的应用程序之间进行一些交互。我从我的第一个应用程序中获得了第一个输出([1]列表、[2]data.frame&[3]data.frame)。我想用它在一个新的应用程序中应用新的功能,这个应用程序最终将成为我的最终仪表板。问题是,既然对象在全局环境中是非反应性的,它们都是列表类型,即使我使用as.data.frame函数(如下所示)。我不知道这是否是原因,但我只是发现它错了,在我的服务器功能中找不到它。知道为什么吗

# --------------------------------------- Global --------------------------------------- #

# Set working directory -> Ctrl+Shift+H & Open the app folder
setwd("~/Programación en R/Shiny app/Client 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 needed packages 
source('additional_scripts/packages.R')

# Load LDA model outcome, topic names & raw data
model <- readRDS("LDA_output.2020-01-02.rds")
as.data.frame(model[[1]][3])
lda_model    <<- model[[1]][1]
dtm          <<- as.data.frame(as.matrix(model[[1]][2]))
doc_top_dist <<- as.data.frame(as.matrix(model[[1]][3]));doc_top_dist <- doc_top_dist[[1]][[1]]
top10_lamda0 <<- as.data.frame(as.matrix(model[[2]]))
full_data    <<- as.data.frame(as.matrix(model[[3]]))
rm(model)
#--------------------------------------- User Interface ---------------------------------------#
ui <- fluidPage( 
  theme = shinytheme("cerulean"), 

  navbarPage("Analysis",

             #--- Home Tab (Global View)
             tabPanel("Global View",
                      sidebarPanel(),
                      DT::dataTableOutput("mela1"),
                      DT::dataTableOutput("mela2")
                      ), #tabPanel - Global View  

             tabPanel("",
                      ) #tabPanel - 

  ) #navbarPage
) #fluidPage
#--------------------------------------- Server ---------------------------------------#
server <- function(input, output, session) {

  reactive({                                  #Gathering important variables in one only data set
    dtd <- doc_top_dist

    print(dtd)

    highest <- apply(dtd, 1, which.max)                             #set highest prob topic  

    print(highest)

    swap <<- function(vec, from, to) {
      tmp <- to[ match(vec, from) ]
      tmp[is.na(tmp)] <- vec[is.na(tmp)]
      return(tmp)
    }

    topic_names <<- colnames(top10_lamda0)

    print(topic_names)

    topic <- swap(highest , 1:length(topic_names), topic_names)     

    dtd <- cbind(topic,dtd)                                         #+ max topic
    dtd$id <- as.character(1:nrow(dtd))                             #+ id column
    vars <- cbind(data$year, data$Ultimate.Parent, data$id, data$IP.Cost, data$Publication.Country)
    colnames(vars) <- c("year", "parent", "id", "cost", "country")  #+ important variables  
    print(colnames)
    dtd <- merge(vars, dtd,  by = "id")
    dtd <<- as.data.frame(dtd)
  })

  output$mela2 <- DT::renderDataTable({
    DT::datatable(full_data, options = list(pageLength = 3, lengthMenu = c(3,30,60)))
  })
  output$mela1 <- DT::renderDataTable({
    DT::datatable(dtd, options = list(pageLength = 3, lengthMenu = c(3,30,60)))
  })
}
shinyApp(ui, server)
#-----------------------------------------全局-----------------#
#设置工作目录->Ctrl+Shift+H&打开应用程序文件夹
setwd(“~/Programación en R/shinny应用程序/客户端仪表板应用程序”)
#----------------初始化程序------------------#
#在控制台中打印:全局脚本开始运行
打印(“global.R”)
#允许在屏幕上显示特定错误,而不是显示一般错误
选项(shinny.sanitize.errors=FALSE)
#加载所需的包
source('其他_脚本/包.R')
#加载LDA模型结果、主题名称和原始数据

模型
dtd
仅在
反应式表达式中具有作用域,因此它对
渲染数据表不可见。Add
dtd错误已停止,但当我在
reactive
函数末尾添加dtd时,仍然没有给我数据表,也没有在控制台上打印dtd。也没有给我全局环境上的dtd,即使我使用的是reactive是否被调用过?仅供将来参考,
reactive
是否每次我使用它时都需要给它起个名字?我不知道你的意思。听起来是另一个问题。