使用Shiny将server.R中的读取数据传递到ui.R中

时间:2019-07-18 11:20:45

标签: r shiny shiny-server

ui.R 中,我首先读取了固定的样本数据

datT2<-fread(paste0('./data/','30062019KRB.csv'),header=TRUE, sep=";",stringsAsFactors = FALSE , encoding="UTF-8")

提取数据结构。 但是,像30062019KRB.csv这样的许多数据,其结构彼此有些许差异。

enter image description here

ui的下一步中,我选择一个名称或一个文件并将其传递给server.R

ui.R

 selectInput(inputId = 'date',
          label = 'Stichtag:',
          choices = list.files('./data', full.names = FALSE,
                   recursive = FALSE)),

server.R

我根据文件名加载数据(例如:30062018KRB.csv)

  data <- reactive({
    infile <- input$date
    if (is.null(infile)){
      return(NULL)
    }
    daS<-fread(paste0('./data/',infile),header=TRUE, sep=";")
    daS[is.na(data)]<- 0
    daS
  })

现在我的问题是:如何将data <- reactive({ ...的输出传递给ui.R,换句话说,我想将datT2中的ui.R设置为{{1 }}。

我在服务器中尝试过:

data <- reactive({ ...

ui.R

  output$datainput <- DT::renderDataTable({ 
    datein<-data ()
    })

但是它不起作用。 目标:使用用户在datT2<-DT::dataTableOutput("datainput ") 中选择的ui.R中的数据结构。 知道如何将服务器中的读取数据传递给ui.R吗?

我什至在ui.R

ui.R

,并出现以下错误:

datT2<-uiOutput("datainput ")

我只想动态读取Warning: Error in :=: Check that is.data.table(DT) == TRUE. Otherwise, := and `:=`(...) are defined for use in j, once only and in particular ways. See help(":="). 48: stop 47: := 中的数据。像这样:

ui.R

我需要在 selectInput(inputId = 'date', label = 'Stichtag:', choices = list.files('./data', full.names = FALSE, recursive = FALSE)), ... datT2<-fread(paste0('./data/',input$date),header=TRUE, sep=";",stringsAsFactors = FALSE , encoding="UTF-8") 内唱歌JavaScript对象

0 个答案:

没有答案