Appsilon / shiny.react

Use React in Shiny applications.
https://appsilon.github.io/shiny.react
GNU Lesser General Public License v3.0
96 stars 12 forks source link

Handle `shiny.tag.function` dependencies #72

Open kamilzyla opened 1 year ago

kamilzyla commented 1 year ago

Goal

The behavior of this app should be equivalent whether the selectInput() is wrapped in ReactContext() or not:

shinyApp(
  ui = shiny.react:::ReactContext(
    selectInput("select", "Select", c("Apples", "Bananas"))
  ),
  server = function(input, output) {}
)

Right now it gives the following error:

Error in FUN(X[[i]], ...) : 
  Expected a recursive structure built of NULLs, lists and dependencies

Root cause

Let's take a look at deparse(selectInput("select", "Select", c("Apples", "Bananas"))):

structure(
  list(
    # Omitted for brevity.
  ),
  class = "shiny.tag",
  html_dependencies = list(
    structure(
      function() {
        if (is_shiny_app()) {
          shiny::registerThemeDependency(func)
          return(mfunc(get_current_theme()))
        }
        mfunc(bs_global_get())
      },
      class = "shiny.tag.function" # The problem
    )
  )
)

The problem boils down to this: the flattenDeps() function doesn't handle arguments of class shiny.tag.function.