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

Intrusive CSS in shiny app #15

Open
PaulC91 opened this issue Nov 10, 2024 · 2 comments
Open

Intrusive CSS in shiny app #15

PaulC91 opened this issue Nov 10, 2024 · 2 comments

Comments

@PaulC91
Copy link

PaulC91 commented Nov 10, 2024

Hi, thanks for this great visualisation library! I noticed when adding a flowmap to a shiny dashboard that the CSS styling is being applied to the entire html document and overwriting my own CSS rules, causing issues. See example below of before and after adding a flowmap to the dashboard:

# empty dashboard
library(shiny)
library(bslib)

ui <- page_sidebar(
  theme = bs_theme(version = 5L, base_font = "serif"),
  title = "Flowmap Blue",
  sidebar = sidebar(title = "My Sidebar"),
  card(
    card_header("My Card"),
    card_body("Placeholder")
  )
)

server <- function(input, output, session) {}

shinyApp(ui, server)
Screenshot 2024-11-10 at 10 09 18
# add a flowmap
library(shiny)
library(bslib)
library(flowmapblue)

ui <- page_sidebar(
  theme = bs_theme(version = 5L, base_font = "serif"),
  title = "Flowmap Blue",
  sidebar = sidebar(title = "My Sidebar"),
  card(
    card_header("My Card"),
    card_body(flowmapblueOutput("flowmap"))
  )
)

server <- function(input, output, session) {
  output$flowmap <- renderFlowmapblue({
    flowmapblue(
      locations = ch_locations,
      flows = ch_flows,
      mapboxAccessToken = Sys.getenv('MAPBOX_ACCESS_TOKEN'),
      clustering = TRUE,
      darkMode = TRUE,
      animation = FALSE
    )
  })
}

shinyApp(ui, server)
Screenshot 2024-11-10 at 10 10 21

You can see that the flowmap background colour has been applied to the entire document body, fonts have changed and the flowmap has filled the entire card element, hiding the header title area.

Is there a way to ensure any flowmap styling is only applied within its container (the card body in this case) ?

Thanks!

@ilyabo
Copy link
Member

ilyabo commented Nov 10, 2024

Not sure if there's a workaround for the current version, but I'll keep this in mind for the next one so that the styles are isolated.

@e-kotov
Copy link
Collaborator

e-kotov commented Nov 10, 2024

@ilyabo I am guessing this is related to #14 and the fact that CSS is hardcoded into the https://github.com/FlowmapBlue/flowmapblue.R/blob/master/inst/htmlwidgets/lib/flowmap-blue.min.js file, unlike other htmlwidget-based packages, e.g. here https://github.com/davidgohel/ggiraph/tree/master/inst/htmlwidgets/lib/ggiraphjs-0.8.10

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

No branches or pull requests

3 participants