Discussion: View Thread

HTML output

  • 1.  HTML output

    Posted 05-09-2016 23:33

    Do you provide output from R, SAS, or other software in HTML format?   Do clients request it?  Should statisticians know HTML or another mark-up language now?

    ------------------------------
    Georgette Asherman
    ------------------------------


  • 2.  RE: HTML output

    Posted 05-09-2016 23:44

    Within R, the need for directly creating html output has been replaced with nice tools for creating reporting directly from code.  Check out the knitr package (http://yihui.name/knitr/), which is able to create reports in html as well as able to interface with LaTeX.

    ------------------------------
    Christopher Holloman
    Information Control Company



  • 3.  RE: HTML output

    Posted 05-09-2016 23:45

    Hi Georgette, 

    My most recent clients requested HTML or Word reports.  In R Studio, these are easy to produce with the R Markdown language.  If you would like to see an easy example of producing such documents, you can drop me an e-mail at isabella@ghement.ca and I'll send you one tomorrow. 

    Best, 

    Isabella

    ------------------------------
    Isabella Ghement
    Ghement Statistical Consulting Company Ltd.



  • 4.  RE: HTML output

    Posted 05-10-2016 10:03

    Hi Isabella,

     

    Can you please show me an example?

    Thank you,

     

    Milena

     



    ------Original Message------

    Hi Georgette, 

    My most recent clients requested HTML or Word reports.  In R Studio, these are easy to produce with the R Markdown language.  If you would like to see an easy example of producing such documents, you can drop me an e-mail at isabella@ghement.ca and I'll send you one tomorrow. 

    Best, 

    Isabella

    ------------------------------
    Isabella Ghement
    Ghement Statistical Consulting Company Ltd.
    ------------------------------


  • 5.  RE: HTML output

    Posted 05-09-2016 23:47

    For SAS output (a.k.a. "voluminous output") I typically provide a pdf of the results and an Excel workbook with the summary statistics (parameter estimates, AIC values, contrasts, etc. all in separate worksheets using ODS followed by PROC EXPORT).  In addition I include a Word document that "explains" what and why things were done:  a repeat of the objectives, any issues with the data, analysis approach, and important summary tables and figures.

    It's extremely rare that I'm asked for HTML output and I would argue that it's not important to be an expert in HTML.  However, for certain consulting areas I do think it is important for us to start learning about reproducible research reporting (if one doesn't know it already) and at least one of the associated mark-up languages.

    ------------------------------
    Jim Baldwin
    Station Statistician
    USDA-Forest Service



  • 6.  RE: HTML output

    Posted 05-09-2016 23:55

    I have used SAS for a long time. In recent years, the SAS ODS system has become a sophisticated, well-structured tool for producing high quality reports in a number of output destinations. Using the ODS system you can prepare:

    • .rtf files including text (with spacing control, unicode symbols, lists, and other components of a structured document
    • .pdf files with the same
    • .html files ditto
    • LaTeX files

    You can include tables and figures in these output destinations. 

    Using this approach, I produce DSMB reports which include the entire report produced out of a SAS run. This allows fully reproducible coding strategies. 

    The main difficulty is that the SAS ODS system is pretty simple to do simple things with, but can be challenging to do more complex documents. For that reason, if you wish really well-structured complex documents, my thought would be to used tagsets.simplelatex to produce LaTeX tables, produce figures with a SAS plotting PROC, and generate the LaTeX document from within SAS by shelling out to the operating system.

    Paul A. Thompson

    PS: If you are interested, I have a talk or two on this, and a partial document.

    ------------------------------
    Paul Thompson
    Director, Methodology and Data Analysis Center
    Sanford Research - Sanford School of Medicine - University of South Dakota



  • 7.  RE: HTML output

    Posted 05-10-2016 10:52
    Paul,

    I would like to see how you integrate SAS and latex if you don't mind sharing.

    Thank you,

    Maria

    -----------------------------------------------------------------------------
    Maria E. Montez Rath
    Engr. Research Associate - Biostatistician
    Division of Nephrology, Department of Medicine
    Stanford University School of Medicine
    1070 Arastradero Road # 3C11C
    Palo Alto, CA. 94304
    Email: mmrath {at} stanford {dot} edu
    Web: https://med.stanford.edu/profiles/maria-emilia-montez-rath


    ------Original Message------

    I have used SAS for a long time. In recent years, the SAS ODS system has become a sophisticated, well-structured tool for producing high quality reports in a number of output destinations. Using the ODS system you can prepare:

    • .rtf files including text (with spacing control, unicode symbols, lists, and other components of a structured document
    • .pdf files with the same
    • .html files ditto
    • LaTeX files

    You can include tables and figures in these output destinations. 

    Using this approach, I produce DSMB reports which include the entire report produced out of a SAS run. This allows fully reproducible coding strategies. 

    The main difficulty is that the SAS ODS system is pretty simple to do simple things with, but can be challenging to do more complex documents. For that reason, if you wish really well-structured complex documents, my thought would be to used tagsets.simplelatex to produce LaTeX tables, produce figures with a SAS plotting PROC, and generate the LaTeX document from within SAS by shelling out to the operating system.

    Paul A. Thompson

    PS: If you are interested, I have a talk or two on this, and a partial document.

    ------------------------------
    Paul Thompson
    Director, Methodology and Data Analysis Center
    Sanford Research - Sanford School of Medicine - University of South Dakota
    ------------------------------


  • 8.  RE: HTML output

    Posted 05-10-2016 11:31

    I agree with previous posters that being able to generate reports directly from R scripts and/or SAS code is important. In forensic or CLIA terms, it is like preserving the 'chain of custody' of the data and results. I now write nearly all reports using either SAS PROC ODSTEXT; or using RStudio with the 'notebook' functionality, which generates a document that includes codes and results, OR using RMarkdown with knitr (as mentioned previously), which is still very simple but allows one to hide the code if desired and to make slightly prettier tables. I tend to show more details under the hood to trainees because I want them to see where the numbers came from, and I show less details and more of the bottom-line to senior investigators. This is easily managed in RMarkdown. The great part is that with both SAS and R, you can re-run the code and get the exact same report, or edit the code to correct problems and get and updated report. With both SAS and R, one can insert explanatory text, add data-driven values to the text, etc. My documents are functional but not necessarily gorgeous. For a really beautiful report, I will need to buff up my very out of date LaTeX skills, but beauty is definitely achievable. Many R books are written entirely in RMarkdown, text, code, problems, graphs and all. I've attached two files, one showing the RMarkdown (*.RMD.txt), and the other showing the results as a WORD document.

    This issue (chain of custody, data provenance, etc) is also very high on the NIH's radar and I expect we will see more push for this:

    http://grants.nih.gov/reproducibility/index.htm

    ------------------------------
    Susan Hilsenbeck
    Professor
    Baylor College of Medicine

    Attachment(s)

    docx
    testmemo.docx   17 KB 1 version
    txt
    testmemo.Rmd.txt   2 KB 1 version


  • 9.  RE: HTML output

    Posted 05-10-2016 12:10

    From a data science perspective:

    I think html, and web technology in general, is becoming a must. Not expert level but you should have enough knowledge to communicate with developers to create small applications and dashboards for clients. Shiny is a way to do this quickly without needing to know html but it may be hard to build a more professional application without some knowledge. However, if you do know html/css/js, you can greatly enhance your shiny applications.

    The clients I worked with were demanding analytics and visual tools. While we still produced lengthy reports (in Word or latex), the applications were the things receiving the *wow* factor and getting us more work. I would say my experience is limited. I was doing mostly reliability engineering / survival analysis in the aerospace/defense and energy sector.  I would also say that reproducing reports was not a priority in these cases; more important was doing the analysis repeatedly after new data streamed in.

    ------------------------------
    Richard Leu



  • 10.  RE: HTML output

    Posted 05-10-2016 16:16

    Hi everyone,

    Several of you have e-mailed me to require access to the promised R Markdown example, so I thought I would share the example with the whole group. The instructions illustrate the production of a Word report from R Studio using R Markdown.  The report can include text, graphs, tables - the usual output produced by a statistical analysis. 

    In a nutshell, the report creation involves creating an R Markdown file and converting it to a Word report by pressing the Knit Word button available in the R Studio. 

    The R Markdown file is a specialized R script which instructs R to include text, graphs and tables in a Word report by using very specific instructions written in the R Markdown language.  The instructions are fairly simple but have to follow the rules of the R Markdown language. 

    Steps 1 - 7 below provide the phases you need to go through to create an empty R Markdown file.   Step 8 requires you to populate the R Markdown file with your own instructions for producing a Word report.  Once these instructions are entered into the R Markdown file and saved, the Word report can be produced by simply pressing the Knit Word button located right above the R Studio script window. 

    Step 1:  Install the following R packages in R Studio:

                    install.packages("rmarkdown")
                    install.packages("knitr")

    Step 2: Require the installed R packages for the current R Studio session:

                    require(rmarkdown)
                    require(knitr)

    Step 3:  Set the working directory for the current R Studio session:

                    Session ---> Set Working Directory ---> Choose Directory...

    Step 4: Open a new R Markdown file from the R Studio menu:

                  File ---> New File ---> R Markdown...

    Step 5:  In the New R Markdown window:

    • Select the type of the R Markdown file to be Document  (in the left panel);
    • Specify the title of the document as Report (in the right panel);
    • Write down your name in the Author box (in the right panel);
    • Specify the Default Output Format of the document as Word (in the right panel);   [Other possibilities of Output Format include HTML or PDF.]
    • Press the OK button to save all of the above changes.

    Step 6:  Select the default contents of the R Markdown file you have just created with Ctrl + A  and delete everything you selected so that you start out with a fresh, empty file.

    Step 7: Save the empty R Markdown file by pressing the keys Ctrl + S, entering the file name Report.Rmd and then pressing the Save button.  [Note the .Rmd extension assigned to the R Markdown file.]

    Step 8: Populate the R Markdown file with appropriate instructions.  [See below for a specific example of instructions.] Keep saving the file at regular time intervals by pressing the keys Ctrl + S

    Step 9:  Press the button Knit Word on the R Studio menu to produce a Word report from the R Markdown file.  If all goes well, the Word report will pop-up on your screen. 

                                                                                                                              ~.~

    So the only missing piece of information concerns the R Markdown instructions to be inserted in the R Markdown file in Step 8 above.  Here is an example of R Markdown instructions to get you started  - simply copy and paste these instructions in your R Markdown file as part of Step 8, save the file and then proceed with Step 9.  [Whenever you launch a new R Markdown file, it is populated with some default commands, so you will need to delete all of those commands and start typing - or copying and pasting - the commands below instead.  Note the special conventions used for styling the report text, as well as the use of ```{r}   before you enter a block of R commands for producing tables or graphs, followed by the use of ``` at the end of that block.  When working with R packages, you will need to require all packages needed to run the R code embedded in your R Markdown file. Additionally, you will need to read all of your data sets as part of the file.]

    ---
    title: "Report"
    author: "Isabella Ghement"
    date: "May 10, 2016"
    output: word_document
    ---




    This is some text.
     
    *This text is styled in italics.*

    ** This text is styled in bold.**



    # First level header

    ## Second level header

    ### Third level header

    #### Fourth level header

    ##### Fifth level header

    ###### Sixth level header




    A horizontal rule can be implemented using three hyphens.

    ---




        
    This is a reference line.

    This is a new paragraph.

    This is the current paragraph.\

    This is a separate line in the current paragraph.




    This is a bulleted list:

    * Item a
    * Item b

    This is an ordered list:

    1. Item 1
    2. Item 2
    3. Item 3

    This is a bulleted list with a sub-list for one of the items:

    * Item a
          + Sub-item 1
          + Sub-item 2
    * Item b

    This is an ordered list with a sub-list for one of the items:

    1. Item 1
       + Sub-item 1
       + Sub-item 2
    2. Item 2
    3. Item 3



    ```{r, echo=FALSE, message=FALSE, fig.width=6, fig.height=5}
       require(car)
       require(ggplot2)

       ggplot(data=Duncan, aes(x=income, y=prestige, group=type)) +
       geom_point(aes(colour=type))
    ```




    ```{r, message=FALSE, kable}
       require(knitr)
       require(car)

       model    kable(summary(model)$coef, digits=2)
    ```

    Let me know if you were able to produce the Word report after following the instructions in this e-mail.   

    You can also produce your Word report from the command line using the command: 

    rmarkdown::render("Report_Name.Rmd")  

    where Report_Name.Rmd is the name of your R Markdown file.  In this case, the Word report will be dumped in your working directory for R Studio, so you can open it with: 

    browseURL("Report_Name.docx")

    Note that, if you have white spaces in your R Markdown file name, R Studio will replace them with hyphens when creating the Word Report.  For example, Report Name.Rmd will become Report_Name.docx.

    For more details on producing reports with R Markdown, you can consult the following links: 

    http://rmarkdown.rstudio.com/

    http://blog.rstudio.org/2014/08/01/the-r-markdown-cheat-sheet/

    Best regards,

    Isabella


    Isabella R. Ghement, Ph.D.
    Ghement Statistical Consulting Company Ltd.
    301-7031 Blundell Road, Richmond, B.C., Canada, V6Y 1J5
    Tel: 604-767-1250
    Fax: 604-270-3922
    E-mail: isabella@ghement.ca
    Web: www.ghement.ca 

    ------------------------------
    Isabella Ghement
    Ghement Statistical Consulting Company Ltd.
    E-mail: isabella@ghement.ca



  • 11.  RE: HTML output

    Posted 05-11-2016 10:05
    Hi Isbella,

       Thanks.  I have used R Markdown a little but this really helps.

    Best, Jack


    ------Original Message------

    Hi everyone,

    Several of you have e-mailed me to require access to the promised R Markdown example, so I thought I would share the example with the whole group. The instructions illustrate the production of a Word report from R Studio using R Markdown.  The report can include text, graphs, tables - the usual output produced by a statistical analysis. 

    In a nutshell, the report creation involves creating an R Markdown file and converting it to a Word report by pressing the Knit Word button available in the R Studio. 

    The R Markdown file is a specialized R script which instructs R to include text, graphs and tables in a Word report by using very specific instructions written in the R Markdown language.  The instructions are fairly simple but have to follow the rules of the R Markdown language. 

    Steps 1 - 7 below provide the phases you need to go through to create an empty R Markdown file.   Step 8 requires you to populate the R Markdown file with your own instructions for producing a Word report.  Once these instructions are entered into the R Markdown file and saved, the Word report can be produced by simply pressing the Knit Word button located right above the R Studio script window. 

    Step 1:  Install the following R packages in R Studio:

                    install.packages("rmarkdown")
                    install.packages("knitr")

    Step 2: Require the installed R packages for the current R Studio session:

                    require(rmarkdown)
                    require(knitr)

    Step 3:  Set the working directory for the current R Studio session:

                    Session ---> Set Working Directory ---> Choose Directory...

    Step 4: Open a new R Markdown file from the R Studio menu:

                  File ---> New File ---> R Markdown...

    Step 5:  In the New R Markdown window:

    • Select the type of the R Markdown file to be Document  (in the left panel);
    • Specify the title of the document as Report (in the right panel);
    • Write down your name in the Author box (in the right panel);
    • Specify the Default Output Format of the document as Word (in the right panel);   [Other possibilities of Output Format include HTML or PDF.]
    • Press the OK button to save all of the above changes.

    Step 6:  Select the default contents of the R Markdown file you have just created with Ctrl + A  and delete everything you selected so that you start out with a fresh, empty file.

    Step 7: Save the empty R Markdown file by pressing the keys Ctrl + S, entering the file name Report.Rmd and then pressing the Save button.  [Note the .Rmd extension assigned to the R Markdown file.]

    Step 8: Populate the R Markdown file with appropriate instructions.  [See below for a specific example of instructions.] Keep saving the file at regular time intervals by pressing the keys Ctrl + S

    Step 9:  Press the button Knit Word on the R Studio menu to produce a Word report from the R Markdown file.  If all goes well, the Word report will pop-up on your screen. 

                                                                                                                              ~.~

    So the only missing piece of information concerns the R Markdown instructions to be inserted in the R Markdown file in Step 8 above.  Here is an example of R Markdown instructions to get you started  - simply copy and paste these instructions in your R Markdown file as part of Step 8, save the file and then proceed with Step 9.  [Whenever you launch a new R Markdown file, it is populated with some default commands, so you will need to delete all of those commands and start typing - or copying and pasting - the commands below instead.  Note the special conventions used for styling the report text, as well as the use of ```{r}   before you enter a block of R commands for producing tables or graphs, followed by the use of ``` at the end of that block.  When working with R packages, you will need to require all packages needed to run the R code embedded in your R Markdown file. Additionally, you will need to read all of your data sets as part of the file.]

    ---
    title: "Report"
    author: "Isabella Ghement"
    date: "May 10, 2016"
    output: word_document
    ---




    This is some text.
     
    *This text is styled in italics.*

    ** This text is styled in bold.**



    # First level header

    ## Second level header

    ### Third level header

    #### Fourth level header

    ##### Fifth level header

    ###### Sixth level header




    A horizontal rule can be implemented using three hyphens.

    ---




        
    This is a reference line.

    This is a new paragraph.

    This is the current paragraph.\

    This is a separate line in the current paragraph.




    This is a bulleted list:

    * Item a
    * Item b

    This is an ordered list:

    1. Item 1
    2. Item 2
    3. Item 3

    This is a bulleted list with a sub-list for one of the items:

    * Item a
          + Sub-item 1
          + Sub-item 2
    * Item b

    This is an ordered list with a sub-list for one of the items:

    1. Item 1
       + Sub-item 1
       + Sub-item 2
    2. Item 2
    3. Item 3



    ```{r, echo=FALSE, message=FALSE, fig.width=6, fig.height=5}
       require(car)
       require(ggplot2)

       ggplot(data=Duncan, aes(x=income, y=prestige, group=type)) +
       geom_point(aes(colour=type))
    ```




    ```{r, message=FALSE, kable}
       require(knitr)
       require(car)

       model    kable(summary(model)$coef, digits=2)
    ```

    Let me know if you were able to produce the Word report after following the instructions in this e-mail.   

    You can also produce your Word report from the command line using the command: 

    rmarkdown::render("Report_Name.Rmd")  

    where Report_Name.Rmd is the name of your R Markdown file.  In this case, the Word report will be dumped in your working directory for R Studio, so you can open it with: 

    browseURL("Report_Name.docx")

    Note that, if you have white spaces in your R Markdown file name, R Studio will replace them with hyphens when creating the Word Report.  For example, Report Name.Rmd will become Report_Name.docx.

    For more details on producing reports with R Markdown, you can consult the following links: 

    http://rmarkdown.rstudio.com/

    http://blog.rstudio.org/2014/08/01/the-r-markdown-cheat-sheet/

    Best regards,

    Isabella


    Isabella R. Ghement, Ph.D.
    Ghement Statistical Consulting Company Ltd.
    301-7031 Blundell Road, Richmond, B.C., Canada, V6Y 1J5
    Tel: 604-767-1250
    Fax: 604-270-3922
    E-mail: isabella@ghement.ca
    Web: www.ghement.ca 

    ------------------------------
    Isabella Ghement
    Ghement Statistical Consulting Company Ltd.
    E-mail: isabella@ghement.ca
    ------------------------------


  • 12.  RE: HTML output

    Posted 05-10-2016 09:30

    I do not provide HTML output as a matter of common practice; usually a .pdf or .xlsx is more appropriate. That said, if you're doing GIS work in R, such as creating a map, then .html is all but a necessity. (Example: I recently was asked to create an interactive map and did so using the tmap and leaflet packages. HTML output is the only way I know of to render such a project useful.)

    ------------------------------
    Tim Young
    Senior Analyst-Statistics & Analytics
    Southwestern Illinois College



  • 13.  RE: HTML output

    Posted 05-10-2016 15:02

    It has been really nice seeing all the different answers here. I focus on my bread and butter tools and then learn on an as-needed basis. I am also a keep it simple person, anything I haven't been able to figure out in R/SAS/etc I have been able to find at one or the other of these sites:

    W3Schools Online Web Tutorials

    Learn to Code HTML & CSS

    I would like to add that I have only been using R for about a year but really enjoying it combined with R Studio.

    Jesse

    ------------------------------
    Jesse Sharp
    Owner, Sr. Statistician
    Sharp Statistical Sciences