2016-11-09 7 views
0

ファイルに含まれる変数の名前をselectInputに表示しようとしています。アイデアは、ユーザーがアプリケーションにファイルをアップロードし、彼はselectInput内の任意の変数を選択できるということです。私はこれをしようとしているが、私は間違いを認識していない。私はこの答えを見つけましたが、それは私を助けませんでした。 Selecting record date with selectInput in shiny RShinyのselectInputに関する問題

これはUi.Rコードです。私はselectInputの名前を取得しません。

library(shiny) 
ui<-fluidPage(
    titlePanel(title = "Prueba"), 
    sidebarLayout(
    sidebarPanel(
     fileInput('file1', 'Cargar archivo', 
       accept = c(
        'text/csv', 
        'text/comma-separated-values', 
        'text/tab-separated-values', 
        'text/plain', 
        '.csv', 
        '.tsv' 
       ) 
    ), 
     checkboxInput('header', '¿Contiene Encabezado?', TRUE), 
     radioButtons('sep', 'Delimitador', 
        c(Comma=',', 
        "Punto y coma"=';', 
        Tab='\t'), 
        ','), 
     radioButtons('quote', 'Quote', 
        c(Ninguna='', 
        'Dobles'='"', 
        'Simples'="'"), 
        '"'), 
     radioButtons('resume', 'Summary', 
        c('Individual', 
        'Múltiple'), 
        inline = TRUE), 
     conditionalPanel("input.resume === 'Individual'", 
         selectInput('xcol', 'Variable X', names("fileInput$file1"), 
            selected = names("fileInput$file1")[[1]]) 
         ) 
    ), 
    mainPanel(h3("Muestra del archivo cargado:"), 
       tableOutput('contents'), 
       verbatimTextOutput("summary") 
    ) 
) 
) 
+0

あなたはserver.Rでファイルを読み込む必要があり、その後選択入力 – HubertL

答えて

0

これが行う方法の一例です。

library(shiny) 
ui<-fluidPage(
    titlePanel(title = "Prueba"), 
    sidebarLayout(
    sidebarPanel(
     fileInput('file1', 'Cargar archivo', 
       accept = c(
        'text/csv', 
        'text/comma-separated-values', 
        'text/tab-separated-values', 
        'text/plain', 
        '.csv', 
        '.tsv' 
       ) 
    ),selectInput('xcol', 'Variable X', columns())), 
    mainPanel(h3("Muestra del archivo cargado:"), 
       tableOutput('contents'), 
       verbatimTextOutput("summary") 
    ) 
) 
) 
server <- function(input, output, session){ 
    columns <- reactive({ 
    df <- read.table(input$file1$datapath) 
    names(df) 
    }) 
    observe({ 
    if(!is.null(input$file1)) 
     updateSelectInput(session, "xcol", choices=columns())}) 
} 

shinyApp(ui, server) 
+0

こんにちは@HubertLに感謝を更新するupdateSelectInput()を使用します。あなたの答えは、私が望むものを得るために私を導いた。パラメータの列()でエラーが発生したため、いくつかの変更を加えました。 – Jrgsua83

+0

これは私のコードです:私は、私はselectInput( 'xcol'、 '変数X'、 "")サーバー< - 関数(入力、出力、セッション)を変更しました{ tableData < - reactive({ inFile < - input $他FILE1 (!is.null(INFILE))なら、{ read.csv(INFILE $データパス、ヘッダ=入力$ヘッダ、9月=入力の$ 9月、 引用=入力$引用) } { リターン(NULL ) }}) ({ updateSelectInput( セッション、 "xcolという"、 選択肢=名(たtableData())) を})観察 – Jrgsua83

関連する問題