1
「fileInput」ウィジェットによってインポートされたデータセットの列の名前を値の選択肢とする「selectInput」ウィジェットを作成したいとします。selectInputの値のリスト
"selectInput"ウィジェットの "choices"パラメータへの引数として、データセットの名前を "tableOutput"しようとしましたが、機能しません。ウィジェットで私が得る唯一の選択肢は、「名前」、「ID」、「クラス」です。
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)
「selectInput」ウィジェットの選択肢として輸入したデータセットの列の名前を使用する方法があります:
ここで私が使用したコードですか?
ありがとう、ありがとうございます!今私はもっと理解するようにしようと思う... :) – Loyushka
これはあなたが探していたものなら答えを受け入れてください –