Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bslib_page): Set global theme temporarily during render #815

Merged
merged 4 commits into from
Oct 5, 2023

Conversation

gadenbuie
Copy link
Member

@gadenbuie gadenbuie commented Oct 4, 2023

This is a draft proposal that fixes #813. In essence, it attaches the page-level theme to the bslib_page classed object in the "bs_theme" attribute. I then modified print.bslib_page() and as.tags.bslib_page() (not sure if that's necessary) to temporarily set the global theme using this attribute.

In #813 the slider in the following example is only partly styled, with this fix bs_dependency_defer() correctly uses the current theme.

library(crosstalk)
library(leaflet)

# Use crosstalk to create a client-side filter between the map and slider
quake_dat <- SharedData$new(quakes)
map_filter <- filter_slider("mag", "Magnitude", quake_dat, ~mag)
map_quakes <- leaflet(quake_dat) |> addTiles() |> addCircleMarkers()

page_sidebar(
  title = "Client-side filtering",
  sidebar = map_filter,
  # Can also put other bslib components here
  # like cards, value boxes, etc.
  map_quakes
)
Before After
image image

R/print.R Outdated Show resolved Hide resolved
@cpsievert
Copy link
Collaborator

cpsievert commented Oct 5, 2023

@gadenbuie thanks for this, I like the simplicity/usefulness/correctness tradeoff.

This does, however, sort of make #477 a more universal problem. I'm thinking we'll address that by making htmltools::save_html a S3 method (in a follow up PR)?

@cpsievert cpsievert marked this pull request as ready for review October 5, 2023 22:20
@cpsievert
Copy link
Collaborator

Sorry to merge before giving you final approval, but this'll make the follow up PR easier to get setup

@cpsievert cpsievert merged commit bee0b80 into main Oct 5, 2023
1 check passed
@cpsievert cpsievert deleted the feat/static-global-theme branch October 5, 2023 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slider handle is in wrong location in Crosstalk example
2 participants