2015-12-07 71 views
0

我無法使用renderTable。這是我得到的錯誤:渲染表不能在Shiny中工作

錯誤UseMethod(「xtable」):因爲沒有適用的方法「xtable」適用於類「性格」

同樣的目標,我想最終輸出是僅2列

  1. 串聯2-4列
  2. 第5列

#server.R 
shinyServer(function(input, output) { 

    content_data <- renderTable({ 

    ga$getData(id, start.date="2015-10-01", end.date=Sys.Date()-1, 
       metrics = "ga:pageViews", 
       dimensions = "ga:date, ga:day, ga:month, ga:year", 
       sort = "ga:date", 
       filter = paste0("ga:[email protected]/tp", input$text))[,2:5] 
    }) 
    output$table1 <- renderTable(content_data()) 
}) 

#ui.R 
shinyUI(fluidPage(

    textInput("text", label = h3("City"), value = "Enter city name..."), 

    hr(), 
    fluidRow(column(12, tableOutput("table1"))) 

)) 
+0

的[無表中未在閃亮顯示了(http://stackoverflow.com/questions/34127605/reactive-table-not-showing-up-in-shiny) –

+0

如果你瞭解可能的複製問題..請你幫忙 – Akshit

回答

0

要調用內renderTablerenderTable。嘗試與此服務器功能:

shinyServer(function(input, output) { 
    output$table1 <- renderTable({ 
     ga$getData(id, start.date="2015-10-01", end.date=Sys.Date()-1, 
       metrics = "ga:pageViews", 
       dimensions = "ga:date, ga:day, ga:month, ga:year", 
       sort = "ga:date", 
       filter = paste0("ga:[email protected]/tp", input$text))[,2:5] 
    })   
}) 

對於串聯,你必須renderTable之前對數據進行處理。像這樣的東西應該工作(下次請張貼可重現的例子)。

shinyServer(function(input, output) { 

content_data <- reactive({ 
    df<-ga$getData(id, start.date="2015-10-01", end.date=Sys.Date()-1, 
      metrics = "ga:pageViews", 
      dimensions = "ga:date, ga:day, ga:month, ga:year", 
      sort = "ga:date")[,2:5] 
    #return concatenated 2-4 and 5 
    cbind(paste(df[2],df[3],df[4]),df[5]) 
}) 

output$table1 <- renderTable(content_data) 
}) 
+0

非常感謝! – Akshit

+0

如何在我的UI基礎table1上添加圖表。我想創建輸出$ plot1,但我既不能使用content_data也不能使用tabel1。 – Akshit

+0

你應該可以用'renderPlot()'和'content_data()[1]'或者content_data()[2]來創建圖表。 – GPierre