strboul / supreme

Generate UML diagrams of Shiny modules
Other
60 stars 5 forks source link

Minimal shiny app with shiny >= 1.5.0 syntax (using `moduleServer`) #12

Open mevers opened 3 years ago

mevers commented 3 years ago

Hi.

I am unable to get supreme to run on a simple test app. Most supreme examples I could find are based on apps using the older (and now (soft-)deprecated) callModule syntax and not on the more recent (shiny >= 1.5.0) moduleServer syntax. I'm not sure if this is the cause of my problems or if there is something else going on.

My app has ui.R and server.R in a root folder, along with module files in folder ./R (this is a/the recommended file structure for a shiny app in an R package); a minimal example looks like this:

sample_app
├── ui.R
├── R
│   └── about.R
└── server.R

with the following files

ui.R

library(shinydashboard)

dashboardPage(
    skin = "blue",
    header = dashboardHeader(),
    sidebar = dashboardSidebar(about_ui("about")),
    body = dashboardBody()
)

R/about.R

library(shiny)
library(shinyalert)

about_ui <- function(id) {
    ns <- NS(id)
    tagList(
        useShinyalert(),
        actionButton(
            ns("about"),
            label = "About the dashboard",
            width = "200px",
            icon = icon("dashboard")))
}

about_server <- function(id) {
    moduleServer(
        id,
        function(input, output, session) {
            observeEvent(input$about, {
                shinyalert(title = "Title", text = "Main text", html = TRUE)
            })
        }
    )
}

# Demo function
demo_about <- function() {
    ui <- fluidPage(about_ui("demo"))
    server <- function(input, output, session)  {
        about_server("demo")
    }
    shinyApp(ui, server)
}

server.R

library(shiny)

server <- function(input, output, session) {    
    about_server("about")    
}

Upon running

files <- c("ui.R", "server.R", "R/about.R")
obj <- supreme(src_file(files))
graph(obj)

I get

image

At first I thought that perhaps the demo_about function in the module causes problems but that doesn't seem to be the case. I am unsure how to proceed and/or debug this.

strboul commented 3 years ago

Thanks for the reproducible code. Clearly, supreme hasn't been designed for moduleServer and I am afraid that there is no easy way to adapt the new syntax without undergoing major refactoring. I need to think a while about how to proceed with this.

mevers commented 3 years ago

Ah that's a real shame. I'd love to see supreme work with current shiny syntax. For what it's worth, the moduleServer syntax was introduced around 12 months ago (see e.g. Modularizing Shiny app code, Mastering Siny) and IMO are important steps forward towards facilitating more consistent shiny app code base management and production-level shiny app development.

Perhaps a note on the GH page stating that supreme does not work with current shiny versions (yet) would be helpful. Alternatively,

shiny (< 1.5.0)

in the Imports.

mevers commented 3 years ago

PS. Just double checked the DESCRIPTION and shiny (>= 1.5.0) is definitely wrong in that case. Perhaps a typo? Should be < 1.5.0 to avoid issues with current moduleServer.

strboul commented 3 years ago

I no longer use Shiny on daily basis and I wasn't really aware of the new changes. Unfortunately, I don't have time to work on it but I'll be happy to review a PR & get you familiar with the codebase if you'd like to take a chance.

Perhaps a note on the GH page stating that supreme does not work with current shiny versions (yet) would be helpful.

It's working with the latest Shiny version (1.6.0) but doesn't work with the new module syntax. I'm sure there's still a lot of applications around with the old module structrure. I'll add a note to the README. Thanks.