wch / webshot

Take screenshots of web pages from R
http://wch.github.io/webshot/
227 stars 40 forks source link

unable to use tabset id as selector #88

Open zac-garland opened 4 years ago

zac-garland commented 4 years ago

Hi Winston

if we start off with the base Rmd template and create a tabset

## {.tabset .tabset-fade}

### R Markdown
plot

### Including Plots
other plot

and render to test_tabset.html

it produces two id's #r-markdown & #including-plots

when i try to use these as selectors, I am unable to screenshot the content of any tab other than the first.

is this an issue with how Rmarkdown defines tabs or webshot? I'm aware that you can't navigate to the tabs like a normal html page, e.g. test_tabset.html#including-plots won't take you to the second tab, and I'm wondering if that is the reason. Do you know of any workaround?

# location of html doc
f_path <- here("inst","test_tabset.html")

# find level 3 tabs and convert to selectors
pg_screen <- read_html(f_path) %>%
  html_nodes(".level3") %>%
  html_attr("id") %>% 
  paste0("#",.)

# create file paths
f_paths <- paste0(snakecase::to_snake_case(pg_screen),".png")

# screenshot
webshot(f_path,
        file = f_paths,
        selector = list(pg_screen))