dreamRs / esquisse

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

Esquisse as submodule gives empty ui aesthetics and plot #247

Closed CorneeldH closed 1 year ago

CorneeldH commented 1 year ago

Hi there,

Beautiful package!

I want to use esquise as a submodule within an other module, however I can't get it to work. The bare bones of my app:


library(shiny)
library(dplyr)
library(esquisse)

esquisseServer <- function(id) {
  moduleServer(id, function(input, output, session) {

    ## TODO Some other special stuff which is why I want esquisse as submodule
    data_rv2 <- reactiveValues(
      data = iris %>% select(-Sepal.Length),
      name = "iris selected"
    )

    esquisse_server(
      id = id,
      data_rv = data_rv2,
      import_from = NULL
    )

  })
}

esquisseUI <- function(id) {

  esquisse_ui(id = id,
              header = FALSE,
              # dont display gadget title
              container = esquisseContainer(height = "700px"))

}

ui <- fluidPage(

  fluidRow(
    esquisseUI("esquisse_submodule")
  ),
  fluidRow(
    esquisse_ui(
      id = "esquisse_head",
      header = FALSE, # dont display gadget title
      container = esquisseContainer(height = "700px")
    )
  )
)

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

  esquisseServer("esquisse_submodule")

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

  esquisse_server(
    id = "esquisse_head",
    data_rv = data_rv,
    import_from = NULL
  )

}

shinyApp(ui, server)

The esquisse_submodule shows up, but the ui aesthetics and plot remain completely empty. The controls are present but nothing can be selected. This in contrast with the esquisse_head that works out of the box. What step am I missing to use esquisse as submodule?

Thanks!


PS: I was wondering whether you are interested in exporting more helper functions and in general increase extensibility even further. This would increase the number of use cases for the package and would allow others, like myself, to build their own 'layers' more easily.

See also my comment on: https://github.com/dreamRs/esquisse/issues/34#issuecomment-1367963672

pvictor commented 1 year ago

Hello, in a module you have to use the module's namespace explicitly in the UI part, and use the according ID in the server, in your code you mix module's ID and content of the module ID. Here's a working example :

esquisseServer <- function(id) {
  moduleServer(id, function(input, output, session) {

    ## TODO Some other special stuff which is why I want esquisse as submodule
    data_rv2 <- reactiveValues(
      data = iris %>% select(-Sepal.Length),
      name = "iris selected"
    )

    esquisse_server(
      id = "esquisse",
      data_rv = data_rv2,
      import_from = NULL
    )

  })
}

esquisseUI <- function(id) {
  ns <- NS(id)
  esquisse_ui(
    id = ns("esquisse"),
    header = FALSE,
    # dont display gadget title
    container = esquisseContainer(height = "700px")
  )
}
CorneeldH commented 1 year ago

Thanks, my bad indeed!

Any thoughts on: "I was wondering whether you are interested in exporting more helper functions and in general increase extensibility even further. This would increase the number of use cases for the package and would allow others, like myself, to build their own 'layers' more easily."

pvictor commented 1 year ago

Sure it can be considered, which functions in particular ? Can you open a new issue on this subject ?