dreamRs / esquisse

RStudio add-in to make plots interactively with ggplot2
https://dreamrs.github.io/esquisse
Other
1.76k stars 228 forks source link

Error when using n_geoms = 1 #272

Open williamorim opened 3 weeks ago

williamorim commented 3 weeks ago

Setting n_geoms = 1 in esquisse_ui() leads to the following error when dragging any variable into the Y axis.

Warning: Error in if: missing value where TRUE/FALSE needed
  3: runApp
  2: print.shiny.appobj
  1: <Anonymous>

Tested with the following minimal example using esquisse 2.0.0:

library(esquisse)
library(shiny)
library(ggplot2)

ui <- fluidPage(

  titlePanel("Use esquisse as a Shiny module"),

  sidebarLayout(
    sidebarPanel(
      radioButtons(
        inputId = "data", 
        label = "Select data to use:", 
        choices = c("mpg", "diamonds", "economics")
      )
    ),
    mainPanel(
      tabsetPanel(
        tabPanel(
          title = "esquisse",
          esquisse_ui(
            id = "esquisse", 
            n_geoms = 1,
            header = FALSE # dont display gadget title
          )
        ),
        tabPanel(
          title = "output",
          tags$b("Code:"),
          verbatimTextOutput("code"),
          tags$b("Filters:"),
          verbatimTextOutput("filters"),
          tags$b("Data:"),
          verbatimTextOutput("data")
        )
      )
    )
  )
)

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

  data_r <- reactiveValues(data = iris, name = "iris")

  observe({
    data_r$data <- get(input$data)
    data_r$name <- input$data
  })

  results <- esquisse_server(
    id = "esquisse",
    data_rv = data_r
  )

  output$code <- renderPrint({
    results$code_plot
  })

  output$filters <- renderPrint({
    results$code_filters
  })

  output$data <- renderPrint({
    str(results$data)
  })

}

shinyApp(ui, server)

My system

> R.version
               _                           
platform       aarch64-apple-darwin20      
arch           aarch64                     
os             darwin20                    
system         aarch64, darwin20           
status                                     
major          4                           
minor          3.2                         
year           2023                        
month          10                          
day            31                          
svn rev        85441                       
language       R                           
version.string R version 4.3.2 (2023-10-31)
nickname       Eye Holes
pvictor commented 3 weeks ago

Hello,

Thanks for reporting this. If you set n_geoms = 1 in esquisse_server as weel the error should disappear :

results <- esquisse_server(
  id = "esquisse",
  data_rv = data_r,
  n_geoms = 1
)

I'll investigate further.

Victor

williamorim commented 3 weeks ago

It worked for me. Thank you Victor!