dreamRs / esquisse

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

Factor errors while trying to utilise Esquisse Shiny modules #62

Closed bkmargetts closed 5 years ago

bkmargetts commented 5 years ago

Hi,

I'm trying to reproduce some of Esquisse's functionality using the Shiny modules referenced in the documentation without relying on the fact that much of this functionality is accessible through the main Esquisse interface.

I've been having some trouble parsing reactive output from the coerce module over to the esquisse ggplot2 UI. When coercing a variable to a factor and 'saving' the changes via a button, I get the following error - Error in Summary.factor: ‘max’ not meaningful for factors. I'm not clear where this is being called or why one of the modules is trying to determine the max value for a coerced factor. The issue may be my Shiny code, or it may be a bug. Let me know your thoughts, thanks!

ui.R script:

library('esquisse')
navbarPage("Navbar",
           tabPanel("Read-in data",

                    hr(),
                    selectInput('in_dat', 'Select a dataset to use:', c('Iris Demo Dataset','mtcars'), multiple=F, selectize=TRUE, selected = NULL),
                    actionButton("read_dat_button", "Read-in data"),
                    DT::dataTableOutput("mytable")
           ),
           tabPanel('Coerce Variables',
                    fluidPage(
                        tags$h2("Coerce module"),
                        fluidRow(
                            column(
                                width = 4,
                                coerceUI(id = "esquisse"),
                                actionButton("save_changes", "Save Changes")
                            ),
                            column(
                                width = 8,
                                verbatimTextOutput(outputId = "print_result"),
                                verbatimTextOutput(outputId = "print_names")
                            )
                        )
                    )
           ),
           tabPanel('Plot data',
                    fluidPage(
                        fluidRow(
                            mainPanel(
                                tags$div(
                                    style = "height: 700px;", # needs to be in fixed height container
                                    esquisserUI(
                                        id = "esquisse", 
                                        header = FALSE, # dont display gadget title
                                        choose_data = FALSE # dont display button to change data
                                    )
                                )
                            )
                        )
                    )
           )

)

server.R script:

shinyServer(function(input, output) {

    # default dataset
    data_r <- reactiveValues(data = iris, name = "iris")    # dataset for updating

    # read-in dataset button
    observeEvent(input$read_dat_button, {
        withProgress(message = 'Reading-in Dataset', detail = '...', value = 0, {
            incProgress(1/length(input$in_dat))

            if(input$in_dat == "Iris Demo Dataset"){
                data_r$data <- iris
                data_r$name <- "Iris Demo Dataset"
            } else{
                data_r$name <- "mtcars"
                data_r$data <- mtcars
            }
        })
    })

    # render data table
    output$mytable = DT::renderDataTable({
        data_r$data
    })

    # ggplot2 builder    
    callModule(module = esquisserServer, id = "esquisse", data = data_r)

    # coerce variables
    result <- callModule(module = coerceServer, id = "esquisse", data = data_r, reactiveValuesSlot = "data")

    # return coerce variables output
    output$print_result <- renderPrint({
        str(result$data)
    })
    output$print_names <- renderPrint({
        result$names
    })

    # update ggplot2 builder with coerce varibles data
    observeEvent(input$save_changes, {
        data_r$data <- result$data
    })

})
bkmargetts commented 5 years ago

Apologies for the code formatting - not sure what happened there!

pvictor commented 5 years ago

Hello Ben, Thanks for reporting the issue, backtrace was indeed opaque... It was a problem generating the filter expression in filter_DF module. Should work now.

Victor

PS : I'll respond to your email too, quick answer is we've no concern you use {esquisse} as described.

bkmargetts commented 5 years ago

Thanks Victor, that seems to have fixed it.

All the best, Ben