2016-09-19 42 views
0

我想用selectInput函數得到表格輸出。 我必須導入(不上傳)不同的csv文件來代替對象錯誤1,2,3,4,但是當我這樣做時,我在mainPanel中得不到正確的輸出。請幫助我在正確的位置導入csv文件,以便我可以在mainpanel中將表格作爲輸出。如何使用selectInput函數獲取表格或數據框作爲R閃亮應用程序中的輸出?

library(shiny) 

ui <- shinyUI(fluidPage(
titlePanel(h3("PUMA", style = "color:black")), 
sidebarLayout(
sidebarPanel(
    tags$head(
    tags$style("body{backgroud-color: pink;}")), 
    selectInput("mydata", "ERROR MESSAGE:", 
       choices = c("Clamping lever closing not detected-Error number 7/31"="error1", 
         "Filter paper wrong or not inserted-Error number 30/20"="error2", 

         "Device is heating up (working temp. not reached yet) Heating Option-Error number 32/51"="error3", 

         "Door is open (Timeout key)-Error number 15/100"="error4")     
) 
), 
    mainPanel(tabsetPanel(
    tabPanel(h2("TABLE", style = "color:red"), verbatimTextOutput ("mydata")), 
    #tabPanel(h2("ERROR", style = "color:red"), verbatimTextOutput("ERROR")), 
    tags$head(tags$style("#mydata{color:blue; 
         font-size: 17px; 
         font-style: bold 
         }")) 
), 
    width = 12) 
    ))) 

server <- shinyServer(function(input, output){ 

output$mydata <-renderPrint ({ 
     input$mydata 
     })  
}) 

    shinyApp(ui = ui, server = server) 
+0

不清楚自己想要什麼。你期望的正確輸出是什麼?要上傳csv,您可以嘗試[this](http://shiny.rstudio.com/gallery/file-upload.html)。 – Jimbou

+0

在error1中有一個數據幀,我希望該數據幀作爲輸出。例如從sidebarpanel如果我選擇「夾緊槓桿關閉未檢測到 - 錯誤號碼7/31」,那麼我應該得到一個數據框,它存儲在對象error1作爲我的主面板輸出。 –

回答

0

render函數實際上返回所選擇的項目,作爲你的input,而不是對象本身的字符串。你可以用在list所有對象或使用get

選項1個

# put all objects in a list 
mDat <- list(error1 = cars, error2 = airquality, error3 = chickwts, error4 = co2) 


server <- shinyServer(function(input, output){ 
    output$mydata <- renderPrint ({ 
     mDat[[input$mydata]] 
    })  
}) 

選項2

# This assumes that you have the objects error1, ..., error4 in the environment 

server <- shinyServer(function(input, output){ 
    output$mydata <- renderPrint ({ 
     get(input$mydata) 
    })  
}) 
相關問題