2016-12-03 19 views
0

我有興趣編寫一個函數,它將一個數據框作爲輸入,並根據數據框中的信息通過knitr作爲輸出返回一個html頁面。如何在R函數中輸出html文件?

這是那種我想寫功能的僞碼的:

htmlOuput <- function(Df) { 
    newDf<-someManipulation(Df) 
    meltedDf<-melt(Df) 
    g<-ggplot(meltedDf) 
    return (html(g)) # This is the part that I am not sure about 
    } 

有沒有辦法以輸出HTML頁面,通過knitr函數的輸出?

+0

'browseURL的操縱(臨時文件中(f = '的.html'))'' – rawr

+0

g'是存儲ggplot對象,而不是data.frame。 – alistaire

+0

我知道'g'是一個ggplot對象,所以我想通過ggplot在html文件中生成繪圖 – DKangeyan

回答

0

經過一番研究,我發現調用一個rmarkdown文件在函數內渲染是最好的選擇。

htmlOuput <- function(Df,meta = NULL, cacheable = NA) { 
    rmarkdown::render('./report.rmd',params=list(output_file = report.html)) 
} 

report.rmd將包含數據幀

newDf<-someManipulation(Df) 
meltedDf<-melt(Df) 
g<-ggplot(meltedDf) 
g 
0

我想你採取了艱難的方式。

一個簡單的方法是使用htmlTable

我已經使用,要導出爲HTML,很容易使用。

+0

htmlTable似乎只適用於表格,但我所尋找的是一個html報告,主要是來自給定數據框架的數據 – DKangeyan

相關問題