1

I am interested in writing a function where it takes a data frame as an input and returns an html page via knitr as an output based on the information in the data frame.

Here is sort of the psuedocode of the function that I wanted to write:

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
  } 

Is there a way to output an html page as a function output via knitr ?

4
  • browseURL(tempfile(f = '.html')) Commented Dec 3, 2016 at 15:11
  • g is a stored ggplot object, not a data.frame. Commented Dec 3, 2016 at 15:16
  • I know that g is a ggplot object, so I want the plot generated through ggplot rendered in the html file Commented Dec 4, 2016 at 2:38
  • @rawr Isn't browseURL to load an HTML file, I wanted to render the plot that I generate into an html file Commented Dec 4, 2016 at 3:01

2 Answers 2

1

After some research I found that calling an rmarkdown file to render within a function to be the best option.

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

Where the report.rmd will contain the manipulation of the data frame

newDf<-someManipulation(Df)
meltedDf<-melt(Df)
g<-ggplot(meltedDf)
g
Sign up to request clarification or add additional context in comments.

Comments

0

I guess you took the hard way.

An easy approach would be to use htmlTable

I have used that to export to html and it is easy to use.

1 Comment

htmlTable seem to only work for tables, but what I am looking for is a html report mainly with figures from the given data frame

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.