Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shiny Client Errors: Cannot read properties of null (reading 'deps') #128

Closed
pawelru opened this issue Sep 3, 2024 · 6 comments
Closed

Comments

@pawelru
Copy link

pawelru commented Sep 3, 2024

https://shinylive.io/r/editor/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKcqajGIgEwCu1OAGcMAcwpxm1AJQAdCHSYsOo1CwDWdCHEUQlaVAAIAPAFoTtCLVLslJk-yikoJgLwmu1APou3dgBJLCCAZU9rRlpROVxHEz4hEVFIpOExBwgnJ1IYXwA3FlooehFfJiIAd1EZBzAANWLSkRMAIUZq2sYFMAMnAwMlUQALG1YAQXR2YwASQVpcEznugpkDMABfAF0gA

I think it's due to this change in the htmlwidgets: r-wasm/htmlwidgets@892798f

console log

shiny.min.js:2 TypeError: Cannot read properties of null (reading 'deps')
    at shinyBinding.renderValue (htmlwidgets.js:515:44)
    at e.<anonymous> (shiny.min.js:2:174316)
    at m (shiny.min.js:2:166780)
    at Generator.<anonymous> (shiny.min.js:2:168103)
    at Generator.next (shiny.min.js:2:167139)
    at R_ (shiny.min.js:2:172750)
    at s (shiny.min.js:2:172948)
    at shiny.min.js:2:173009
    at new Promise (<anonymous>)
    at e.<anonymous> (shiny.min.js:2:172889)

When I enter the JS debugger I can see the following:
image
data is null thus data.deps throws

Outside of shinylive everything is fine. Entering debugger in the same place does not show null value.

I'm trying to create a base shiny example for this to debug this easier but the example above shows that it is possible to have null value there so it would make sense to handle this somehow.

I have seen #124 but adding loading dependency from external CDS does not help.

@pawelru
Copy link
Author

pawelru commented Sep 3, 2024

similar issue: r-wasm/webr#330

@pawelru
Copy link
Author

pawelru commented Sep 3, 2024

Minimal reprex

https://shinylive.io/r/editor/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAGwEsAjAJykYE8AKAZwAtaJWAlAB0IdJiw71OY4aIbM27ACIAVWSICutAAQAeALTbUUAOZwA+p1oATOPRbsR27Vdv3G2gLwubdh0+dtAm44AgBreiIADwBJCFQNUkcIQMC+BNIY6y9tITBGOABHPNwA1OooejhqHLyCwu0ANyhqDTgSssDm1rgcgDEAQQAZAGUAUU7ZZwFSlO1VAHlEjPYiZcSs2rAovNl1CE44RkajvUMAMw0IAlJaEnZ0xNxtNdIMgW0QANeMgBIos7aAoQWyMVTsL5zZz1B7xRK-epTNKMWicAIAX1k6JEIh4fFYA3Q7C0OS0z0Ox1O3gpJ0YsjA6IAukA

library(shiny)
library(bslib)
library(DT)

ui <- page_sidebar(
  sidebar = sidebar(
    checkboxInput(
      inputId = "req",
      label = "req value",
      value = FALSE
    )
  ),
  DTOutput(outputId = "x")
)

server <- function(input, output) {
  output$x <- renderDT({
    req(input$req)
    iris
  })
}

shinyApp(ui = ui, server = server)

@georgestagg
Copy link
Collaborator

I believe I have tracked down the underlying issue. That is, I now know how and why the problematic null object is being generated.

The issue is related to the patches made to webR's distribution of Shiny so that it can work well under WebAssembly. I have fixed the problem and made a new release of the package at https://github.com/r-wasm/shiny/releases.

With this latest build, the example app works without generating any errors:
Screenshot 2024-09-06 at 09 17 20

Shinylive won't automatically pick up the change, but I will include upgrading the Shiny R package as part of some other work I am currently undertaking. Once that work has all been merged, it should fix the issue on shinylive.io etc.

@georgestagg
Copy link
Collaborator

The above reprex (here) should now run successfully without errors on shinylive.io when toggling the req() switch.

The associated PR for the R Shinylive package to include the latest version of the assets is here: #131

@seanbirchall
Copy link

@georgestagg I think this fixes an issue I've been experiencing that I originally opened here ramnathv/htmlwidgets#487, but now lives here seanbirchall/scrapeable#1.

I created a bandaid solution using a delay that works ok... but I originally developed this mini htmlwidget so that I could avoid using some type of session$sendCustomMessage with a delay or debounce pattern. Ultimately that's what I ended up doing though using debounce. Without it I get this data.deps error which for some reason I believed must've been an htmlwidgets issue before opening here.
https://github.com/seanbirchall/scrapeable/blob/6db104ce40d8f42a513891e36654c0908ab2ecda/app/R/mod_df_viewer.R#L152C1-L152C30

@georgestagg
Copy link
Collaborator

georgestagg commented Oct 9, 2024

Yes, I think the raising of the TypeError: Cannot read properties of null (reading 'deps') error means that this is almost certainly the same underlying problem. The issue is not with htmlwidgets itself, it is just very easy to trigger using widgets. It seems another way to trigger the bug was by using req().

The underlying issue was in my Wasm patches to R Shiny so that it can run in Shinylive. The patches did not correctly raise conditions to be handled, instead internally returning a NULL where an R condition should be raised. This filtered out to the application and caused the "Cannot read properties of null" error in the JavaScript side of things.

It should now (hopefully) be fixed on https://shinylive.io/r/examples/, and once #131 is merged also in the outputs of the R Shinylive package and Quarto documents. I'll close the issue once that happens.

@seanbirchall If the issue still remains after that point please feel free to open a new issue at posit-dev/shinylive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants