ddaya11
ddaya11

Reputation: 3

RMarkdown plot doesn't show in final knit output

I'm working with RMarkdown and created a report using the gt package. Before I knit the document, the graph output shows 2 parts: "R Console" and "shiny.tag.list". While the "shiny.tag.list" has the table, R Console is what appears after i knit the document, "no non-missing arguments to min; returning Infno non-missing arguments to max; returning -Inf". How do I get it to show the table? Is there a way to address the R Console comments so it won't appear?

PS. Knit output is in Microsoft Word.

gt_tbl <- 
    df_tbl %>% 
    gt(rowname_col="date")

# removes date so you can add a line alignment for that column
  
gt_tbl <- 
    gt_tbl %>% 
    tab_stubhead(label="date")
# adds the line alignment + new label for column you just took out name for  

 gt_tbl <- 
   gt_tbl %>% 
   tab_header(
     title=md("**Weekly Screener Report**"),
     subtitle= {current_range}) %>% 
   tab_style(
     style=list(
       cell_fill(color="light blue"),
       cell_text(weight="bold")
     ),
     locations = cells_body(
       columns=vars(week_total)
     )
   )
# md("**text**") bolds "text"
 # tab_style() adds color where you want it, can be done to rows as well
 # tab_header is for title and subtitle
 
  
# Create 2 row groups w/ 'tab_row_group()' function
 # Group the rows in opposite order you want to see it in
gt_tbl <- 
  gt_tbl %>% 
    tab_row_group(
      group="current",
      rows= 5:8  
  ) %>% 
  
    tab_row_group(
      group="former",
      rows= 1:4
  )

# view table
gt_tbl

before_knit_rconsole

before_knit_plot

after_knit_output

Upvotes: 0

Views: 1522

Answers (1)

MKR
MKR

Reputation: 1700

I can reproduce the error.

But first, what you see are in your output are warnings. You can get rid of these by setting the header of the chunk as follows:

{r, warning=FALSE}

A reproducible example:

---                                                                                         
title: "test"                                                                               
output: word_document                                                                       
---                                                                                         
                                                                                            
```{r setup, include=FALSE}                                                                 
knitr::opts_chunk$set(echo = TRUE)                                                          
library(gt)                                                                                 
```                                                                                         
                                                                                            
                                                                                            
```{r, warning=FALSE}                                                                       
gt_tbl <-                                                                                   
  gt::gtcars                                                                                
                                                                                            
gt_tbl %>% gt(rowname_col = "mfr")                                                          
```    

When I run this code, I don't get the table printed out in the .docx. If I change to pdf_document the table appears.

A quick search indicated that word outputs are not supported (https://www.danieldsjoberg.com/gtsummary/articles/rmarkdown.html). But I might be wrong.

Upvotes: 1

Related Questions