我想在一个变量名列表中加载一个CSV文件,例如
"var_A", "var_B", "var_C"
并在GUI中为每个变量名创建一个数字输入列表。我想我需要通过uiOutput
函数,但不知道这样做。这是我正在尝试做的有点草稿
ui <- bootstrapPage(
fileInput('file1', 'Choose CSV File', accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv'))
# list of numeric inputs
#uiOutput("list_numeric_inputs")
)
server <- function(input,output) {
data_set <- reactive({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
data_set<-read.csv(inFile$datapath, header=F)
})
# # list of numeric inputs
# output$list_numeric_inputs <- renderUI({
# # If missing input, return to avoid error later in function
# if(is.null(input$data_set()))
# return()
#
# # Get the data set value for variable name
# for (i in 1:nrow(data_set)) {
# numericInput("...", paste0(data_set[i]), value = 0.)
# }
# })
}
shinyApp(ui, server)
答案 0 :(得分:1)
1)你的例子没有用(header=input$header,sep=input$sep, quote=input$quote
没有输入)
2)您还没有input$dataset
data_set <- reactive
3)所以工作一个:
library(shiny)
ui <- bootstrapPage(
fileInput('file1', 'Choose CSV File', accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv')),
# list of numeric inputs
uiOutput("list_numeric_inputs")
)
server <- function(input,output) {
data_set <- reactive({
inFile <- input$file1
if (is.null(inFile))
return(NULL)
data_set<-read.csv(inFile$datapath,header = F)
})
# list of numeric inputs
output$list_numeric_inputs <- renderUI({
# If missing input, return to avoid error later in function
if(is.null(data_set()))
return()
# Get the data set value for variable name
lapply(data_set(),function(i){
numericInput(paste0(i,"_ID"), i, value = 0.)
}
)
})
}
shinyApp(ui, server)