Closed johnaclouse closed 5 years ago
Hi John,
This is a css matter... If you use v0.9.0, you can insert a chunk such as this one before the call to dfSummary()
:
```{r, results='asis', echo=FALSE}
st_css()
For earlier versions, refer to this [vignette](https://cran.r-project.org/web/packages/summarytools/vignettes/Recommendations-rmarkdown.html) to include the appropriate css.
Hope this helps!
Thank you Dominic. That resolved the issue.
I had previously included the st_css()
in the first code chunk of the Rmd file, but it didn't appear to work. Including it in the same code chunk as the call to dfSummary
did have the desired result.
I also found that if I did not specify the method attribute (just omitted it) instead of using method = 'render'
that the formatting appeared as desired.
Hi, quick question, I didn't think it was necessary to open a new issue..
For various reasons, I'm finding it really convenient to be able to use dfSummary on a list of dataframes. However, I am not able to do this without running into the same issue about the summary statistics on a single line.
For example
library(summarytools)
knitr::opts_chunk$set(echo = FALSE, results='asis')
data <- lapply(c("cars", "iris"), get)
This works just fine:
st_css()
print(dfSummary(cars), method = 'render')
But when I try to do this, I end up with the summary stats on one line issue.
st_css()
lapply(data, function(x) print(dfSummary(x), method = 'render'))
I was able to get things to work with the old way shown in the vignettes, but of course this looks a bit nicer and it's more convenient not having to worry about setting the correct options.
Hi Katie,
It's not clear to me why this happens. I'll try to address it eventually... Meanwhile have you tried setting some options globally with st_options()
? It could at least make the syntax less redundant.
Thx
I ran into the same issue as above: method = 'render' results in all the Stats/Values on a single line.
However, unlike others, the issue is NOT resolved by using results='asis'
This is in an R Notebook. Here is the relevant chunk:
```{r, results="asis", echo=FALSE}
library(summarytools)
st_css()
print(dfSummary(train, graph.magnif = 0.75), method = 'render')
Looking into the CSS, I see that, when method = 'browser', the .st-multline class has `white-space: pre`, but when using method='render', .st-multiline does not. If I use RStudio DevTools to add it back in, the problem is fixed.
UPDATE: I took a closer look, and I think I see the problem. st_css renders the style tag into the chunk, but print(dfSummary(df), method='render') prints the output into an iframe inside the chunk. That iframe does not include the style tag. Maybe dfSummary will need to output the style tag itself if we want them to apply inside that iframe?
I'm still looking for a workaround, but if I'm right, there may be other style issues when rendering dfSummary inside a Rnotebook.
Thanks for the info. I haven't done thorough testing for R Notebooks, would you mind creating a reproducible example as a step in that direction? Thx
The following produces the desired output for the stats/value column: each stat (e.g. mean, sd, min) is on a separate line in the cell
Mean (sd) : 49.6 (18.3) min < med < max: 18 < 50 < 80 IQR (CV) : 32 (0.4)
The following places each of the stats on the same line:
Mean (sd) : 49.6 (18.3) min < med < max: 18 < 50 < 80 IQR (CV) : 32 (0.4)
It appears to be a style issue as the text in the cell looks the same. Is there a parameter than one could set to achieve the desired multi-line output using
method = "render"
?