If you are a data scientist or researcher, you will certainly be interested in reproducible research. I have developed several functions to make reports with variable formats from R code.
install.packages("devtools")
devtools::install_github("cardiomoon/webr")You can load the webr package with the folowing R command.
require(webr)Loading required package: webr
require(moonBook) # for data acs Loading required package: moonBook
Sample data sampleData2 is included in webr package. You can see the sampleData2 by folllowing R command.
str(sampleData2)'data.frame': 5 obs. of 3 variables:
$ type : chr "mytable" "table" "plot" "ggplot" ...
$ title: chr "mytable" "iris[1:10,]" "plot" "ggplot" ...
$ code : chr "mytable(sex~.,data=acs)" "df2FlexTable(iris[1:10,])" "plot(iris)" "ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width,color=Species))+geom_point()" ...
Or you can make a table of this data
df2FlexTable(sampleData2)|
|
type |
title |
code |
|
1 |
mytable |
mytable |
mytable(sex~.,data=acs) |
|
2 |
table |
iris[1:10,] |
df2FlexTable(iris[1:10,]) |
|
3 |
plot |
plot |
plot(iris) |
|
4 |
ggplot |
ggplot |
ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width,color=Species))+geom_point() |
|
5 |
Rcode |
Regression Analysis |
summary(mtcars) |
You can make report with a powerpoint format.
data2pptx(sampleData2)You can make report with a docx format.
data2word(sampleData2)You can make report with a HTML format.
data2HTML(sampleData2)You can make report with a pdf format. A LaTex should be installed to your computer to get ‘pdf’ file.
data2pdf(sampleData2)You can get a zipped plot file. Available format is ‘PNG’,‘SVG’ and ‘PDF’.
data2plotzip(sampleData2,format="PNG")You can set the width, height, resolution, units of your plots. You can see the manual of this function by entering the following command.
?data2plotzipIf you are a shiny app develper, you can use my ‘pptxList’ shiny module in your app. Please try the sample shiny app.
shiny::runApp(system.file('pptxList',package='webr'))After loading the shiny app, please click the ‘load sample Data’ button. You can edit the sample data by clicking ‘edit Data’ button. You can download report as a “HTML” or “docx” or “pptx” format. You can download report as a ‘pdf’ file(You have to set the LaTex in your computer).
The followings are the source codes of this app. The source file is very simple. After loading a required package, only three rows of R code make a shiny app. You can use this module in your app freely.
library(shiny)
library(moonBook)
library(webr)
ui=fluidPage(
pptxListInput("pptxlist")
)
server=function(input,output,session){
mydf=callModule(pptxList,"pptxlist")
}
shinyApp(ui,server)