In ui.R, I read at first a fixed sample data
datT2<-fread(paste0('./data/','30062019KRB.csv'),header=TRUE, sep=";",stringsAsFactors = FALSE , encoding="UTF-8")
to extract the data structure.
however there are many data like 30062019KRB.csv whose structure varies a little bit from each other.
In the next step in ui, I choose one name or one file and pass it to server.R
ui.R:
selectInput(inputId = 'date',
label = 'Stichtag:',
choices = list.files('./data', full.names = FALSE,
recursive = FALSE)),
and in server.R:
I load the data based on the file name (for instance: 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
})
Now my question is: How can I pass the output of data <- reactive({ ... to ui.R in other words I want to set datT2 in ui.R as output of data <- reactive({ ....
I tried in server:
output$datainput <- DT::renderDataTable({
datein<-data ()
})
and ui.R
datT2<-DT::dataTableOutput("datainput ")
BUT it does not work.
Goal: To use the structure of the data within ui.R which user selected in ui.R.
Any idea how can I pass the read data in server to ui.R?
I tried even in ui.R
datT2<-uiOutput("datainput ")
and got the following error:
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: :=
I want just to read the data in ui.R dynamically. Something like:
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")
I need something like sing JavaScript objects within ui.R
来源:https://stackoverflow.com/questions/57093296/pass-the-read-data-in-server-r-into-ui-r-using-shiny
