User interface selectInput的值列表
我想创建一个“selectInput”小部件,其值的选择是由“fileInput”小部件导入的数据集中的列的名称 我尝试将数据集的名称“tableOutput”作为“selectInput”小部件的“choices”参数的参数,但它不起作用。我在小部件中得到的唯一选择是“名称”、“id”和“类” 以下是我使用的代码:User interface selectInput的值列表,user-interface,input,server,shiny,output,User Interface,Input,Server,Shiny,Output,我想创建一个“selectInput”小部件,其值的选择是由“fileInput”小部件导入的数据集中的列的名称 我尝试将数据集的名称“tableOutput”作为“selectInput”小部件的“choices”参数的参数,但它不起作用。我在小部件中得到的唯一选择是“名称”、“id”和“类” 以下是我使用的代码: library(shiny) ui <- fluidPage( # Widget for loading data set fileInput("file", l
library(shiny)
ui <- fluidPage(
# Widget for loading data set
fileInput("file", label = h4("Input csv data set")),
# Widget for selecting the variable among names of columns of the data set
selectInput("select.variable", label = h4("Select variable from data set"),
choices = tableOutput("list.var"), selected = 1) # This approach doesn't work
)
server <- function(input, output) {
# The goal was to get the list of names of columns to use it as "choices"
# in the "selectInput" widget
output$list.var <- renderTable({
inFile <- input$file
if (is.null(inFile)) # To avoid error messages when the file is not yet loaded
return(NULL)
# After the file is loaded
data.fr <- read.csv(inFile$datapath)
list.var <- names(data.fr[1,]) # Get the names of the columns of the dataset
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
ui像这样的东西应该可以奏效。我使用renderUI
从数据集创建滑块小部件
library(shiny)
ui <- fluidPage(
# Widget for loading data set
fileInput("file", label = h4("Input csv data set")),
uiOutput("myslider")
)
server <- function(input, output) {
# The goal was to get the list of names of columns to use it as "choices"
# in the "selectInput" widget
output$myslider <- renderUI({
# Widget for selecting the variable among names of columns of the data set
selectInput("select.variable", label = h4("Select variable from data set"),
choices = names(mydata()), selected = 1) # This approach doesn't work
})
mydata <- reactive({
inFile <- input$file
if (is.null(inFile)) # To avoid error messages when the file is not yet loaded
return(NULL)
# After the file is loaded
data.fr <- read.csv(inFile$datapath)
names(data.fr[1,]) # Get the names of the columns of the dataset
})
output$list.var <- renderTable({
mydata()
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
非常感谢你,它很有效!现在,我将尝试更好地理解……:)如果这是你想要的,请接受答案