2015-12-30 7 views
5

मेरे पास एक चमकदार ऐप है जो xlsx/csv फ़ाइल का चयन करता है और इसे सिस्टम पर अपलोड करता है और अपलोड करने के बाद, मैं डेटा तालिका के कॉलम नामों को पॉप्युलेट करना चाहता हूं जिसे मैंने selectInput() या selectizeInput() पर निकाला है।चमकदार ऐप में यूआई से डेटा चुनने के बाद इनपुट() को चुनने के लिए मूल्य (विकल्प) कैसे पास करें?

नीचे कोड उपयोगकर्ता के घटना डेटा फ़ाइल

अपलोड करने ui.R

library(markdown) 
    require(XLConnect) 


    shinyUI(navbarPage(img(class="img-polaroid", 
     src=paste0("http://www.iconsdb.com/icons/preview/black/stackoverflow-5-xl.png")), 

     tabPanel("Table", 
      titlePanel("Select Data"), 
      sidebarLayout(
      sidebarPanel(
       selectInput("fileType", "Select File Type:", 
        c("MS Excel Worksheet (xls,xlsx)" = "xls", 
         "Text/CSV (.csv)" = "csv" 
        ) 
        ), 
       fileInput('file1', 'Choose file to upload', 
        accept = c(
         'text/csv', 
         'text/comma-separated-values', 
         'text/tab-separated-values', 
         'text/plain', 
         '.csv', 
         '.tsv', 
         'application/vnd.ms-excel', 
         'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 
         '.xlsx', 
         '.xls' 
        ) 
       ), 
       tags$hr(), 
       checkboxInput('header', 'Header', TRUE), 
       radioButtons('sep', 'Separator', 
        c(Comma=',', 
         Semicolon=';', 
         Tab='\t'), 
        ','), 
       radioButtons('quote', 'Quote', 
        c(None='', 
         'Double Quote'='"', 
         'Single Quote'="'"), 
        '"'), 
       tags$hr() 


      ), 
      mainPanel(
       dataTableOutput('table') 
      ) 
     ) 

     ), 
     tabPanel("Plot", 
      sidebarLayout(
      sidebarPanel(
       radioButtons("plotType", "Plot type", 
        c("Scatter"="p", "Line"="l") 
       ) 
      ), 
      mainPanel(
       plotOutput("plot") 
      ) 
     ) 
     ), 
     navbarMenu("More", 
      tabPanel("Summary", 
      verbatimTextOutput("summary") 
     ) 
     ) 
    )) 

server.R

shinyServer(
    function(input, output, session) 
     { 
     output$plot <- renderPlot({ 
     plot(data$Count,data$Sales, type=input$plotType) 
     }) 

     output$summary <- renderPrint({ 
     summary(data) 
     }) 

     output$table <- renderDataTable({ 
     inFile <- input$file1 

     if (is.null(inFile)) 
      return(NULL) 
     if(input$fileType=='csv'){ 
      table1<-read.csv(inFile$datapath, header = input$header, 
       sep = input$sep, quote = input$quote) 
      return(table1) 
     } else if(input$fileType=='xls'){ 
      table1 <- readWorksheetFromFile(inFile$datapath, sheet=1) 
     } 

     }) 
    } 
) 
का प्रतिनिधित्व करता है

पर्याप्त मेला, मेरे पास अब इनपुट की एक कार्य प्रणाली है जो एक्सेल स्रोत या टेक्स्ट/सीएसवी से डेटा ले सकती है। उसके बाद, मैं एक गतिशील सूची बनाना चाहता हूं जो colnames(output$table) के मूल्यों को मेरे ui.R पर पास करेगी और इसे निर्दिष्ट स्थान पर रखेगी।

मैं इसे कैसे कर सकता हूं?


मैं How to get vector of options from server.R to ui.R for selectInput in Shiny R App को मेसन DeCamillis के जवाब से uiOutput() उपयोग करने की कोशिश की है, लेकिन आर मुझे फेंक रहा है एक "वस्तु नहीं मिला" त्रुटि।

इसके अलावा, यह हुआ कि मुझे यूआई और सर्वर पर डेटा पास करने में सक्षम होने के लिए reactive() का उपयोग करना होगा। लेकिन कोई सुराग नहीं, मैं इसे कैसे कर सकता हूं।

+0

[यह आलेख] (http://shiny.rstudio.com/articles/dynamic-ui.html) नीचे दिए गए @NicE द्वारा उत्तर को समझने की कोशिश करने वाले किसी भी व्यक्ति के लिए उपयोगी संदर्भ है, या आमतौर पर प्रतिक्रियाशील यूआई के साथ शुरू किया जाता है शाइनी। – alistaire

उत्तर

8

आप अपलोड की गई तालिका को अपने server.R में data चर में संग्रहीत कर सकते हैं और selectInput भरने के लिए आपके द्वारा पोस्ट किए गए लिंक से कोड का उपयोग कर सकते हैं।

अपने server.R में, आप कर सकता है:

data <- reactive({ 
    inFile <- input$file1 
    if (is.null(inFile)) 
     return(NULL) 
    if(input$fileType=='csv'){ 
     table1<-read.csv(inFile$datapath, header = input$header, 
         sep = input$sep, quote = input$quote) 
     return(table1) 
    } else if(input$fileType=='xls'){ 
     table1 <- readWorksheetFromFile(inFile$datapath, sheet=1) 
    } 
    }) 

    output$table <- renderDataTable({ 
    data()  
    }) 

    output$selector <- renderUI({ 
     selectInput("var", "Choose name:", as.list(colnames(data()))) 
    }) 

और अपने ui.R में, uiOutput("selector") जहां सूची बनना चाहते जोड़ें।

+0

और मैं चयनित सर्वर का उपयोग 'server.R' में फिर से कैसे करूं ?? 'प्रिंट (आउटपुट $ चयनकर्ता) 'एक ऑब्जेक्ट आउटपुट नहीं मिला' त्रुटि फेंक रहा है। नीचे दिया गया बयान एक सही तरीका है ?? 'var <-reactive (आउटपुट $ selector <- renderUI ({ selectInput (" var "," नाम चुनें: ", as.list (उपनाम (डेटा())) })) – sunitprasad1

+0

@ sunitprasad1 आपको उपयोग करना चाहिए चयनित चर के मान को सामान्य रूप से प्राप्त करने के लिए 'इनपुट $ चयनकर्ता'। तो आपके पास कुछ ऐसा होगा: 'var <- प्रतिक्रियाशील ({x <- इनपुट $ चयनकर्ता; प्रिंट (x)})'। – user5029763

संबंधित मुद्दे