2015-01-27 2 views
0

R 반짝이를 사용하여 APP를 만들려고합니다. 데이터 (.csv 파일)를 업로드하고 싶습니다. 그런 다음 CSV 파일의 열 이름을 드롭 다운 메뉴에 채 웁니다. 나는 그것을 할 수 없다.R 반짝이에서 드롭 다운 메뉴를 동적으로 채울 수 없습니다

아래의 코드를 참조하십시오 :

---- server.r을 -----

library(shiny) 
options(shiny.maxRequestSize = 32*1024^2) 


shinyServer(


function(input, output){ 

data <- reactive({ 
    file1 <- input$file 
    if(is.null(file1)){return()} 
    read.table(file=file1$datapath,head=TRUE,sep=",") 

}) 

output$sum <- renderTable({ 
    if(is.null(data())){return()} 
    summary(data()) 

}) 

output$table <- renderTable({ 
    if(is.null(data())){return()} 
    data() 
}) 

# the following renderUI is used to dynamically generate the tabsets when the file is loaded. Until the file is loaded, app will not show the tabset. 
output$tb <- renderUI({ 
    if(is.null(data())) 
    h5("no file loaded") 
    else 
    tabsetPanel(tabPanel("Data", tableOutput("table")),tabPanel("Summary", tableOutput("sum"))) 
}) 

    output$col <- renderUI({ 

    selectInput("phenomena", "Select the Phenomena", names(data)) 
    }) 

}) 

----- ui.R -----

library(shiny) 


shinyUI(fluidPage(

titlePanel("Hotspot Analysis of EnviroCar Data"), 
sidebarLayout(
sidebarPanel(

    # uploading the file 
    fileInput("file","Upload *.csv file"), # fileinput() function is used to get the file upload contorl option 

    uiOutput("col") 


), 

mainPanel( uiOutput("tb")) 

) 

)) 

답변

4

것 같아요 문제는 server.R에 있습니다

selectInput("phenomena", "Select the Phenomena", names(data)) 

여기서 괄호없이 data을 사용하고 있으므로 실제로 얻는 것은 data 함수의 소스 코드이고 names(data)NULL입니다. 당신이 필요로하는 건 names(data)names(data())으로 대체하는 것입니다.

관련 문제