2

In an a collaborative work I'm required to use huxtable to visualize some output. So far I have not managed the very basic first step to display a huxtable properly in the Rstudio plot or viewer window.

I'm used to whatever kind of package (ggplot etc.), which all allow you to preview your visualizations in the plot or viewer window eg. plot(mtcars).

However, the output of hux(mtcars[1:5, 1:4]) or huxtable(mtcars[1:5, 1:4]) shows up in the console only, which gives you little idea about how the final product my look like:

> hux(mtcars[1:5, 1:4])
                                          mpg     cyl    disp      hp  
                                         21         6     160     110  
                                         21         6     160     110  
                                         22.8       4     108      93  
                                         21.4       6     258     110  
                                         18.7       8     360     175  

Column names: mpg, cyl, disp, hp```

How to obtain a final output with huxtable? I would not like knit some kine an entire document when playing with some design features.

MsGISRocker
  • 588
  • 4
  • 21
  • You'll have to put the code in a .Rmd document, and then set the Preview to the Viewer pane in Rstudio. Knit the document to preview it. – Phil Dec 27 '20 at 17:07

2 Answers2

0

There is not ideal solution. But, the following does work without needing a markdown file. You first save it to a html file and then view using the viewer() function from rstudioapi...

library(htmltools)
library(rstudioapi)
library(huxtable)

quick_html(hux(mtcars[1:5, 1:4]), file = "huxtable-output.html")
viewer(url = "huxtable-output.html")
Patrick
  • 742
  • 7
  • 19
HoneyBuddha
  • 748
  • 8
  • 15
0

A workaround may be to use huxtable::as_flextable() since a flextable seems to go to the Viewer by default while a huxtable does not.

library(huxtable)
as_flextable(hux(mtcars[1:5, 1:4]))
Patrick
  • 742
  • 7
  • 19