像这样的事情应该会奏效。我用过
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)