posit-dev / r-shinylive

https://posit-dev.github.io/r-shinylive/
Other
147 stars 15 forks source link

Cannot read properties of null (reading 'deps') #75

Closed ydkristanto closed 3 months ago

ydkristanto commented 3 months ago

Hello! I'm encountering an issue while attempting to use the Shinylive app to demonstrate network visualization using {network}, {GGally}, and {plotly} packages. When running the app on localhost, I'm receiving the following error message:

Shiny Client Errors Error on client while running Shiny app Cannot read properties of null (reading 'deps')

Here I provided a reprex of the Shiny app code that I'm using:

library(shiny)
library(plotly)
library(network)
library(GGally)

# Data ----
edge_list <- data.frame(from = c(1, 2, 2, 4), to = c(2, 3, 4, 1))
node_list <- data.frame(
    id = 1:4,
    label = letters[1:4]
)

# UI ----
ui <- fluidPage(
    titlePanel("Reprex: Network Analysis"),
    sidebarLayout(
        sidebarPanel(
            selectInput(
                "nodes",
                "Nodes:",
                c(letters[1:4]),
                selected = letters[2:4],
                multiple = TRUE,
                selectize = TRUE
            )
        ),
        mainPanel(
           plotlyOutput("plot")
        )
    )
)

# Server ----
server <- function(input, output) {
    output$plot <- renderPlotly({
        # Filter
        node_filter <- node_list |>
            filter(label %in% input$nodes)
        # Apply filter
        edge_list <- edge_list |>
            filter(
                from %in% node_filter$id,
                to %in% node_filter$id
            )
        # Create network object
        net <- network::network(
            edge_list,
            vertex.attr = node_filter,
            matrix.type = "edgelist",
            ignore.eval = FALSE
        )
        # Plot the network
        plot <- ggnet2(
            net = net,
            node.color = "black",
            edge.color = "grey"
        )
        # Make it interactive
        ggplotly(plot)
    })
}

# Run the app ----
shinyApp(ui = ui, server = server)

I've run the app in RStudio, and it works fine. I've also checked all the packages; they are already in the Wasm repo, as are their dependencies. Any assistance in resolving this issue would be greatly appreciated. Thank you!

georgestagg commented 3 months ago

I tried running your app on https://shinylive.io/r/ and saw the following message in the console:

Warning: Error in require_namespaces: please install the package 'sna'.  install.packages('sna') 

Does adding library(sna) to your app.R make the app behave as expected? Here is an example on at shinylive.io with the extra line added.

ydkristanto commented 3 months ago

Thanks, @georgestagg, for your assistance. The app works when I add library(sna)!