gadenbuie / xaringanExtra

:ferris_wheel: A playground of enhancements and extensions for xaringan slides.
https://pkg.garrickadenbuie.com/xaringanExtra
Other
449 stars 36 forks source link

Xaringan Slides: panelset doesn't work #162

Closed brianmsm closed 2 years ago

brianmsm commented 2 years ago

I'm not sure what the problem is... as I've been using panelset with no problems so far. I'm going round and round and can't find the error or the solution.

Panelset just doesn't work in this case.

---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, PBC"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
  xaringan::moon_reader:
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)

library(xaringanExtra)
library(tidyverse)
xaringanExtra::use_panelset()

Title

.panelset[ .panel[.panel-name[R Code]

There is text here.

rec1 <- haven::read_sav("https://raw.githubusercontent.com/healthinnovation/curso-introduccion-r-tidyverse/main/sesion_04/data/RECH1.sav")
rec94 <- haven::read_sav("https://raw.githubusercontent.com/healthinnovation/curso-introduccion-r-tidyverse/main/sesion_04/data/REC94.sav")
rec94 <- rec94 %>% 
  mutate(
    HHID = str_sub(CASEID, 1, str_length(CASEID) - 3),
    CASEID = str_sub(CASEID, -2, -1),
    CASEID = as.numeric(CASEID)
  )
rec1 %>%
  inner_join(
    rec94,
    by = c("HHID", "HVIDX" = "CASEID")
  )

]

.panel[.panel-name[Another] More text ] ]



![image](https://user-images.githubusercontent.com/28207224/171992965-c1bf2913-f18c-4334-b8ec-e54dab2609f5.png)
gadenbuie commented 2 years ago

Can you try a couple things for me?

brianmsm commented 2 years ago
  1. If I remove the text before the first chunk, it still doesn't work image

  2. It works if I set eval = FALSE in the code that's going to print the output image

In same way if I only save output in another object such as df image

  1. Yes, it's a spss file (.sav) that contains labels associated to its variables and labels of values in different variables. Printing tibbles has this visualization: image

It could be likely that when representing value labels with square brackets, they interfere with panelset. In fact, I only need to put the output of the first data import for panelset to break:

---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, PBC"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
  xaringan::moon_reader:
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)

library(xaringanExtra)
library(tidyverse)
xaringanExtra::use_panelset()

Title

.panelset[ .panel[.panel-name[R Code]

haven::read_sav("https://raw.githubusercontent.com/healthinnovation/curso-introduccion-r-tidyverse/main/sesion_04/data/RECH1.sav")

]

.panel[.panel-name[Another] More text ] ]


![image](https://user-images.githubusercontent.com/28207224/172028487-16da55a3-16d9-44f7-90e3-7908487f5c7c.png)
brianmsm commented 2 years ago

I've been exploring a bit more... and it's kind of strange. It seems to be related to the use of labels, but also about the number of columns to print on the screen.

If I restrict with the select function to have only a few columns (no matter what they are) so that the printing will fit on the screen, panelset works without problems.

image

If I add one more column in the select, panelset breaks again. image

But, if this additional column is a variable with no associated variable label, panelset doesn't break no matter how much the screen printing is overflowed.

image

I recreated an artificial data by adding data labels with the labelled package, and the problem was reproduced in the same way.

---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, PBC"
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
  xaringan::moon_reader:
    lib_dir: libs
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)

library(xaringanExtra)
library(tidyverse)
xaringanExtra::use_panelset()

Title

.panelset[ .panel[.panel-name[R Code]

library(labelled)

df <- tibble(s1 = c("M", "M", "F"), 
             s2 = c(1, 1, 2),
             s3 = c("P", "B", "B"), 
             s4 = c("M", "M", "F"), 
             s5 = c(1, 1, 2),
             s6 = c("P", "B", "B"),
             s7 = c("M", "M", "F"), 
             s8 = c(1, 1, 2),
             s9 = c("P", "B", "B")) %>%
  set_variable_labels(s1 = "Sex", s2 = "Question") %>%
  set_value_labels(s1 = c(Male = "M", Female = "F"), 
                   s2 = c(Yes = 1, No = 2),
                   s3 = c(Brother = "B", Parents = "P"),
                   s4 = c(Male = "M", Female = "F"), 
                   s5 = c(Yes = 1, No = 2),
                   s6 = c(Brother = "B", Parents = "P"),
                   s7 = c(Male = "M", Female = "F"), 
                   s8 = c(Yes = 1, No = 2),
                   s9 = c(Brother = "B", Parents = "P"))
df %>% 
  select(s1:s8)

]

.panel[.panel-name[Another] More text ] ]



![image](https://user-images.githubusercontent.com/28207224/172028974-840693ef-e19a-4b10-8ed4-cc61343c8c43.png)
gadenbuie commented 2 years ago

Thanks for doing all that exploration! I think it comes down to needing the square brackets to be balanced. In other words it seems [labelled] is okay but [labelled... is not.

This points to issues with the markdown parser used by remarkjs (the slides library used by xaringan), which unfortunately means it's not something I can fix. You'll have to work around it by adjusting the rows or number of columns shown in the preview.