nutterb / pixiedust

Tables So Beautifully Fine-Tuned You Will Believe It's Magic.
179 stars 18 forks source link

reducing white space after html tables #57

Closed nutterb closed 7 years ago

nutterb commented 8 years ago

I have a couple of <br/> tags at the end of the HTML tables. I need to see if these are strictly necessary or if they could be optionally removed.

kgottstine commented 7 years ago

I am running into issues with the white space after html tables, I have been trying to use *** to produce a horizontal line after a table to split up my html report but depending on the number of rows the pixiedust table has, the line either does not show up or shows up behind the middle of the table. I am using the code for the table in a script that will be used to generate many reports and need a fix that will not require manually changing the margin on the bottom of the table, or adding several <br/> tags at the end of the table to get the desired result.

*** works in other portions of my report, after graphs, after chunks of text, I just can't get it to work after the table.

nutterb commented 7 years ago

Without a reproducible example, it's hard to give you specific advice. I can say that there is an argument in the print method that specifies how many linebreaks to put at the end of the table. Compare the output below:

---
title: "Untitled"
output: html_document
---

```{r}
library(pixiedust)

knitr::opts_chunk$set(echo = FALSE)

mtcars %>%
  dust() %>%
  medley_bw() 
```

***

```{r}
mtcars %>%
  dust() %>%
  medley_bw() %>%
  print(linebreak_at_end = 1)
```

***

```{r}
mtcars %>%
  dust() %>%
  medley_bw() %>%
  print(linebreak_at_end = 10)
```

***

As I look at this now, I realize that this argument really ought to reference an option so that it can be set globally.

kgottstine commented 7 years ago

Following is my code to produce the table (you had actually helped me with another issue the other day regarding this table)

```{r SD and Mean Table, echo = FALSE, results = 'asis', warning = FALSE}  
line.table[line.cols] %>%   
  dust(justify = "left") %>%  
  medley_all_borders(part = "table") %>%  
  sprinkle_table(halign = "left", pad = 2.5) %>%  
  sprinkle(rows = which(line.table$`Mean Pass/Fail` == "Fail"), col = "Mean Pass/Fail", 
           bg = "rgba(255, 00, 00, .7)") %>%  
  sprinkle(rows = which(line.table$`Mean Pass/Fail` == "Pass"), col = "Mean Pass/Fail", 
           bg = "rgba(63, 255, 00, .7)") %>%   
  print(asis = FALSE, linebreak_at_end = 1) %>% cat()
```
***
### Plots

Note: the horizontal line follows the end of the chunk.

When I have 2 lines in the table, I get the following output in the html file

capture

Then when I have 20 rows, I get the following output in the html file

capture2

nutterb commented 7 years ago

I just learned something new! The problem is the justify = "left". The solution appears to be using justify = ""). By default, everything is left aligned in HTML, and using justify = "left" sets the table as a kind of float (? but not really?) and messes with all sorts of settings. I'll file another issue to have justify = "left" omit the alignment option from that table so that it behaves properly in the future.

For now, this seems to work.

---
title: "Untitled"
output: html_document
---
```{r SD and Mean Table, echo = FALSE, results = 'asis', warning = FALSE}  
library(pixiedust)
mtcars %>%   
  dust(justify = "") %>%  
  medley_all_borders(part = "table") %>%  
  sprinkle_table(halign = "left", pad = 2.5) %>%  
  sprinkle(rows = which(mtcars$gear == 4), 
           col = "mpg", 
           bg = "rgba(255, 00, 00, .7)") %>%  
  sprinkle(rows = which(mtcars$gear == 3), 
           col = "mpg", 
           bg = "rgba(63, 255, 00, .7)") %>%   
  print(asis = FALSE, linebreak_at_end = 0) %>%
  cat()
```

***
### Plots
kgottstine commented 7 years ago

Thank you very much! I really enjoy using your package, it's made it very easy to customize tables that my company needs to use. We appreciate your quick responses to questions!

nutterb commented 7 years ago

I'm working on this right now, and in pixiedust 0.8, I am going to restrict the options for justify to "center", "none", "left", and "right". This means the code I've given above will break.

Where I have dust(justify = "") will need to be dust(justify = "none").

It still works in the current base to use dust(justify = "none"), so I would recommend making that change now so that you're not surprised when 0.8 comes out later this summer.