For anyone that's curious, this is where I ended up. It's not perfect, and im sure there are better approaches (if you have one, let me know!) I've found that it errors out on non-shiny tags (e.g. svg elements), and full web pages (scripts, js, etc.)
Output:
example:
# libraries ----
# devtools::install_github("zac-garland/zgtools")
# libraries
zgtools::zg_core_libs()
# html and conversion ----
pg <- read_html("https://getbootstrap.com/docs/4.5/components/buttons/")
raw_html <- pg %>%
html_nodes("pre") %>%
.[[1]] %>%
html_text()
# convert html to r and copy to clip
zgtools::raw_html_to_r(raw_html)
# the below section is copied to the clipboard ----
new_fun <- function(primary_1 = "Primary",
secondary_1 = "Secondary",
success_1 = "Success",
danger_1 = "Danger",
warning_1 = "Warning",
info_1 = "Info",
light_1 = "Light",
dark_1 = "Dark",
link_1 = "Link", ...) {
shiny::withTags(
div(
body(
button(
type = "button",
class = "btn btn-primary",
primary_1
),
button(
type = "button",
class = "btn btn-secondary",
secondary_1
),
button(
type = "button",
class = "btn btn-success",
success_1
),
button(
type = "button",
class = "btn btn-danger",
danger_1
),
button(
type = "button",
class = "btn btn-warning",
warning_1
),
button(
type = "button",
class = "btn btn-info",
info_1
),
button(
type = "button",
class = "btn btn-light",
light_1
),
button(
type = "button",
class = "btn btn-dark",
dark_1
),
button(
type = "button",
class = "btn btn-link",
link_1
)
)
)
)
}
# example of usage ----
new_fun() %>%
fluidPage(
bootstraplib::bootstrap(), .,
plotly::plot_ly(mtcars,x = ~mpg,y = ~cyl)
) %>%
htmltools::browsable()
Created on 2020-07-21 by the reprex package (v0.3.0)