Skip to content

Add reportTheme argument to plotlyOutput() for reporting CSS styles #1802

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

Merged
merged 2 commits into from
Jun 26, 2020

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Jun 26, 2020

Adds the ability to access the new CSS styles reported in getCurrentOutputInfo() inside of a renderPlotly() context. For example:

library(shiny)
library(plotly)

ui <- fluidPage(
  tags$style(HTML("body {background-color: black; color: white}")),
  tags$style(HTML("body a {color: orange}")),
  plotlyOutput("p")
)

server <- function(input, output, session) {
  
  output$p <- renderPlotly({
    info <- getCurrentOutputInfo()
    plot_ly(x = 0:10, y = 0:10, color = I(info$accent())) %>%
      layout(
        font = list(color = info$fg()),
        paper_bgcolor = info$bg(),
        plot_bgcolor = info$bg(),
        xaxis = list(
          gridcolor = info$fg(),
          zerolinecolor = info$fg()
        ),
        yaxis = list(
          gridcolor = info$fg(),
          zerolinecolor = info$fg()
        )
      )
  })
  
}

shinyApp(ui, server)

Screen Shot 2020-06-26 at 11 34 02 AM

This'll provide the foundation thematic and ggplotly() need to make this possible

library(shiny)
library(plotly)
library(thematic)

thematic_shiny()

ui <- fluidPage(
  titlePanel("Hello auto theming with ggplotly()"),
  tags$head(
    tags$style(HTML("body{background-color:#444444; color:#e4e4e4}")),
    tags$style(HTML("a{color:#e39777}"))
  ),
  plotlyOutput("p")
)

server <- function(input, output, session) {
  output$p <- renderPlotly({
    p <- ggplot(faithfuld, aes(waiting, eruptions, z = density)) + 
      geom_raster(aes(fill = density)) + 
      geom_contour()
    ggplotly(p)
  })
}

shinyApp(ui, server)

Screen Shot 2020-06-26 at 11 15 28 AM

@cpsievert cpsievert requested a review from schloerke June 26, 2020 15:40
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.

3 participants