2016-02-11 27 views
0

有沒有人有一個想法,我將如何去保存從閃亮的數據表(DT :: renderDataTable)輸出作爲.png?即,我想創建一個按鈕,類似於this button把renderDataDataTable輸出保存爲PNG的按鈕從閃亮

例如,任何人都可以定義一個按鈕,這個表保存爲png:

--- 
output: html_document 
runtime: shiny 
--- 

```{r setup, echo=FALSE} 
library(DT) 

    DT::renderDataTable({ 
     datatable(iris) %>% formatStyle(
     'Sepal.Width', 
     backgroundColor = styleInterval(3.4, c('gray', 'yellow')) 
    ) 
    }) 

``` 
+0

將表中的數據保存到表格的形式爲您的應用程序沒有什麼意義?我還沒有看到很多將表格保存爲圖像的情況.. –

+0

對於包含在我不想加載和纏繞數據的靜態報告中。 – Nick

+0

也看看這裏,也許你可以使用'DT'圖書館做你所有的出口http://stackoverflow.com/questions/24510671/r-shiny-datatables-with-tabletools-and-other-extensions –

回答

1

你的主要任務是如何將表格轉換成PDF格式。 Here aretwo SO questions有關如何做到這一點的答案。

假設您使用這些參考問題(這不是閃亮的相關問題)指出這一部分。我將接近下一個步驟的方法是首先將路徑返回到你,使PDF

createPDF <- function(df) { 
    # create a pdf 
    return(pdf_file) 
} 

然後在閃亮你使用函數創建一個PDF和downloadHandler你只需要複製PDF轉換成您提供給downloadHandler的文件名。事情是這樣的:

### in UI 
downloadButton('downloadPdf', 'Download table') 

### in server 
output$downloadPdf <- downloadHandler(
    filename = function() { 
     "table.pdf" 
    }, 
    content = function(file) { 
     file <- createPDF(df) 
     file.copy(file, "table.pdf") # or something like this 
    } 
) 

我還沒有試過,但,這就是我想嘗試

+0

明智的答案和我將調查的方法。似乎感謝! – Nick