Skip to content

dev ggplot2 appears to break thematic #6317

Closed
rstudio/thematic
#156
@olivroy

Description

@olivroy

Here is my shiny app. Don't really know how to reproduce without shiny (which makes it hard to debug)

I had to do a GitHub search for Internal error: adjust_color() expects an input of length 1 to figure out where this was coming from...

library(shiny)
library(bslib)
library(thematic)
library(ggplot2)

thematic::thematic_shiny()

# Define UI
ui <- fluidPage(
  theme = bs_theme(version = 5, bootswatch = "minty"),

  titlePanel("Shiny App with bslib, thematic, and ggplot2"),

  sidebarLayout(
    sidebarPanel(
      selectInput("dataset", "Choose a dataset:",
                  choices = c("mtcars", "iris")),
      uiOutput("var_select")
    ),

    mainPanel(
      plotOutput("plot")
    )
  )
)

# Define server logic
server <- function(input, output, session) {

  datasetInput <- reactive({
    switch(input$dataset,
           "mtcars" = mtcars,
           "iris" = iris)
  })

  output$var_select <- renderUI({
    req(datasetInput())
    selectInput("variable", "Choose a variable:",
                choices = names(datasetInput()))
  })

  output$plot <- renderPlot({
    req(input$variable)
    ggplot(datasetInput(), aes({{ input$variable }})) +
      geom_histogram(fill = "blue", bins = 20, alpha = 0.7) +
      theme_minimal()
  })
}

# Run the application
shinyApp(ui = ui, server = server)

(app from ChatGPT)

Backtrace

Avis : Error in adjust_color: Internal error: adjust_color() expects an input of length 1
  189: stop
  188: adjust_color
  185: <Anonymous>
  184: mapply
  183: Map
  182: ggplot_build.ggplot
  180: print.ggplot
  175: func
  173: f
  172: Reduce
  163: do
  162: hybrid_chain
  134: drawPlot
  120: <reactive:plotObj>
  100: drawReactive
   87: renderFunc
   86: output$plot
    1: runApp

https://github.com/rstudio/thematic/blob/76513a7ad671257545e34381fc6ab47e8c5eaa80/R/utils.R#L5

(This works as expected with CRAN ggplot2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions