2017-05-03 92 views
1

我在Shiny中使用renderTable來顯示table。我在重命名輸出中的列名時遇到問題。如何重命名閃亮renderTable中的列?

server.R:

reactive.tables <- reactiveValues() 

output$lump.sum <- renderTable(
    if(input$my.password != am.password$password){ 
    data.frame(`There is no` = "report") 
    } else { 
    print(1) 
    reactive.tables$occupancies %>% # sum amounts by company 
     group_by(company) %>% 
     summarise(lump.sum.2 = sum(lump.sum.2), n = n()) %>% 
     na.omit 
    }, 
    colnames(output$lump.sum.2) = c("company", "lump sum", "occupancies") 
) 

重命名列似乎工作的反應方面的罰款之外。然而,每一次我指定此反應數據幀中的colnames說法,我得到以下錯誤:

ERROR: Error sourcing C:\Users\Carlos\AppData\Local\Temp\RtmpmmVUym\fileb803ae92d13 

任何建議,將不勝感激。

+0

凡'$輸出最初annual.sum'定義?它是'輸出$ lump.sum'拼寫錯誤嗎? – Parfait

+0

我不認爲它很重要,因爲我懷疑可以設置引用類似這樣的輸出的colname。但我同意我們需要一個可重複的例子,... – BigDataScientist

回答

2

我想通了。相反瞎搞與renderTable選項,您可以使用重命名()簡單地重命名的列:

output$lump.sum <- renderTable(
    if(input$my.password != am.password$password){ 
    data.frame(`There is no` = "report") 
    } else { 
    print(1) 
    reactive.tables$lump.sum <- reactive.tables$occupancies %>% # sum amounts by company 
    group_by(company.unduplicated) %>% 
    summarise(lump.sum.2 = sum(lump.sum.2), n = n()) %>% 
    na.omit %>% 
    rename(Company = company.unduplicated, Sum = lump.sum.2, Count = n) 
}, 
colnames = TRUE 
) 

Example.