nstrayer / shinysense

A bunch of shiny modules that let shiny sense the world around it.
http://nickstrayer.me/shinysense
Other
206 stars 31 forks source link

The example give an error message : Error: div.st is not a function #54

Open sbenateau opened 3 years ago

sbenateau commented 3 years ago

First, thank you for your work! I am not a developer and I hope my explanations aren't to vague. on two different "computers" the error on the browser is : Error: div.st is not a function No errors in the console nor in the logs on the server

moldach commented 3 years ago

Can confirm that trying the following and clicking Run App produces the Error: div.st is not a function error:


library(shiny)
library(shinysense)
library(tidyverse)
library(keras)

# instantiate the model
model <- application_resnet50(weights = 'imagenet')
ui <- fluidPage(
  theme = shinythemes::shinytheme("flatly"),
  titlePanel("Imagenet Classifier"),
  fluidRow(
    column(width = 7, h3("Webcam"),
           shinyviewr_UI("myCamera", height = '250px') ),
    column(width = 4, offset = 1,  h3('Predictions'),
           plotOutput("predPlot"))
  ),
  h3("Last Photo"),
  imageOutput("snapshot", height = '250px') 
)
server <- function(input, output) {
  #server side call of the viewr module
  myCamera <- callModule(
    shinyviewr, "myCamera" )
  # Watch for photos being taken
  observeEvent(myCamera(), {
    photo_processed <- myCamera() %>% 
      {.*255} %>%  #get image to 0-255 instead of 0-1
      {
        this <- .
        write_rds(this, 'webcam_photo.png')
        this
      } %>% 
      array_reshape(c(1, dim(.))) %>% 
      imagenet_preprocess_input()
    # make predictions then decode and print them
    preds <- model %>% 
      predict(photo_processed) %>% 
      imagenet_decode_predictions(top = 8) %>% 
      .[[1]]
    # Plot predictions
    output$predPlot <- renderPlot({
      preds %>% 
        mutate(
          class_description = str_replace(
            class_description, '_', ' ' )
        ) %>% 
        ggplot(aes(
          x = reorder(class_description, score), 
          y = score) ) + coord_flip() +
        geom_pointrange(aes(ymin = 0, ymax = score))
    })
    # show photo
    output$snapshot <- renderPlot({
      plot(as.raster(myCamera()))
    })
  })
}
# Run the application
shinyApp(ui = ui, server = server)

Error

Webcam
Error: div.st is not a function in /home/mtg/R/x86_64-pc-linux-gnu-library/4.0/shinysense/r2d3/viewr/main.js#26:5
TypeError: div.st is not a function
sbenateau commented 3 years ago

Here is a config that works for me

> sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=fr_FR.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=fr_FR.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=fr_FR.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] shinysense_0.2.0 shiny_1.6.0     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6        magrittr_2.0.1    xtable_1.8-4      R6_2.5.0          rlang_0.4.10     
 [6] fastmap_1.1.0     tools_4.0.4       png_0.1-7         jquerylib_0.1.3   withr_2.4.1      
[11] htmltools_0.5.1.1 ellipsis_0.3.1    yaml_2.2.1        digest_0.6.27     lifecycle_0.2.0  
[16] later_1.1.0.1     base64enc_0.1-3   sass_0.3.1        htmlwidgets_1.5.3 promises_1.1.1   
[21] cachem_1.0.3      mime_0.9          compiler_4.0.4    bslib_0.2.4       r2d3_0.2.3       
[26] jsonlite_1.7.2    httpuv_1.5.5      renv_0.12.5      
moldach commented 3 years ago

Hi @sbenateau thank you for providing your working sessionInfo().

I started a new project with renv and started downloading the specific versions in your config. There were a few times it asked me to install newer packages (so I said no).

install_version("xtable", version = "1.8.4", repos = "http://cran.us.r-project.org")
install_version("R6", version = "2.5.0", repos = "http://cran.us.r-project.org")
install_version("rlang", version = "0.4.10", repos = "http://cran.us.r-project.org")
install_version("fastmap", version = "1.1.0", repos = "http://cran.us.r-project.org")
install_version("png", version = "0.1-7", repos = "http://cran.us.r-project.org")
install_version("jquerylib", version = "0.1.3", repos = "http://cran.us.r-project.org")
install_version("withr", version = "2.4.1", repos = "http://cran.us.r-project.org")
install_version("htmltools", version = "0.5.1.1", repos = "http://cran.us.r-project.org")
install_version("ellipsis", version = "0.3.1", repos = "http://cran.us.r-project.org")
install_version("yaml", version = "2.2.1", repos = "http://cran.us.r-project.org")
install_version("digest", version = "0.6.27", repos = "http://cran.us.r-project.org")
install_version("lifecycle", version = "0.2.0", repos = "http://cran.us.r-project.org")
install_version("later", version = "1.1.0.1", repos = "http://cran.us.r-project.org")
install_version("base64enc", version = "0.1-3", repos = "http://cran.us.r-project.org")
install_version("sass", version = "0.3.1", repos = "http://cran.us.r-project.org")
install_version("htmlwidgets", version = "1.5.3", repos = "http://cran.us.r-project.org")
install_version("promises", version = "1.1.1", repos = "http://cran.us.r-project.org")
install_version("cachem", version = "1.0.3", repos = "http://cran.us.r-project.org")
install_version("mime", version = "0.9", repos = "http://cran.us.r-project.org")
install_version("bslib", version = "0.2.4", repos = "http://cran.us.r-project.org")
install_version("r2d3", version = "0.2.3", repos = "http://cran.us.r-project.org")
install_version("jsonlite", version = "1.7.2", repos = "http://cran.us.r-project.org")
# say no to updating promises to 1.1.1 (just in-case; not tested)
install_version("httpuv", version = "1.5.5", repos = "http://cran.us.r-project.org")
devtools::install_github("nstrayer/shinysense")
> devtools::install_github("nstrayer/shinysense")
Downloading GitHub repo nstrayer/shinysense@HEAD
These packages have more recent versions available.
It is recommended to update all of them.
Which would you like to update?

  1: All                                
2: CRAN packages only                 
3: None                               
4: lifecycle (0.2.0 -> 1.0.0  ) [CRAN]
5: promises  (1.1.1 -> 1.2.0.1) [CRAN]
6: cachem    (1.0.3 -> 1.0.4  ) [CRAN]
7: mime      (0.9   -> 0.10   ) [CRAN]
8: r2d3      (0.2.3 -> 0.2.5  ) [CRAN]

Enter one or more numbers, or an empty line to skip updates:
### Say none here (just in-case)
install.packages('tidyverse')
install.packages('keras')

I'm still getting errors running the demo #55.

The drawr() function which wasn't working before seems to work now #56

The example I provided above crashes Rstudio; however, that's probably just a limitation of my laptop.

I found the following simple example here:

library(shiny)
library(shinysense)
library(tidyverse)

ui <- fluidPage(
  shinyviewrUI("myCamera", height = '200px'),
  imageOutput("snapshot")
)

server <- function(input, output) {
  #server side call of the drawr module
  myCamera <- callModule(
    shinyviewr, "myCamera", 
    outputHeight = 300,
    outputWidth = 400)

  # logic for what happens after a user has drawn their values. 
  observeEvent(myCamera(), {
    photo <- myCamera() 
    print(photo) #print to console for inspection
    output$snapshot <- renderPlot({
      plot(as.raster(photo)) # plot photo
    })
  })
}

# Run the application
shinyApp(ui = ui, server = server)

There were a few adjustments that needed to be made:

library(shiny)
library(shinysense)
library(tidyverse)

ui <- fluidPage(
  shinyviewr_UI("myCamera", height = '400px'),
  imageOutput("snapshot")
)

server <- function(input, output) {
  #server side call of the drawr module
  myCamera <- callModule(
    shinyviewr, "myCamera", 
    output_height = 300,
    output_width = 400)

  # logic for what happens after a user has drawn their values. 
  observeEvent(myCamera(), {
    photo <- myCamera() 
    print(photo) #print to console for inspection
    output$snapshot <- renderPlot({
      plot(as.raster(photo)) # plot photo
    })
  })
}

# Run the application
shinyApp(ui = ui, server = server)

Thank you very much for the help!

great-success

MMenninger commented 3 years ago

I got past div.st but now have a new error.

Error: div.appendChild is not a function in ~/R/renv/cache/v5/R-4.1/x86_64-w64-mingw32/shinysense/0.2.0/db731e0ed89bf5263819da16451c62d7/shinysense/r2d3/viewr/main.js#26:21 TypeError: div.appendChild is not a function

DanyangDai commented 2 years ago

I was having the same problem. I think the problem might be that the ;aterest version of r2d3 does not have div.st as a function. It works for me after changing the verison of r2d3 to "0.2.3". After I did that, the error for div.st is not a function is gone but I am having other errors trying to run the sample code.

SalusDiscovery commented 2 years ago

I also had the div.st error mentioned above and can verify that simply changing the r2d3 package to 0.2.3 fixed the example provided by @moldach on a macOS M1. I was using updated packages of the rest of the packages mentioned above (updated versions shown below).

    Package Version

1: R6 2.5.1 2: Rcpp 1.0.8.3 3: base64enc 0.1-3 4: bslib 0.3.1 5: cachem 1.0.6 6: compiler 4.1.1 7: digest 0.6.29 8: ellipsis 0.3.2 9: fastmap 1.1.0 10: htmltools 0.5.2 11: htmlwidgets 1.5.4 12: httpuv 1.6.5 13: jquerylib 0.1.4 14: jsonlite 1.8.0 15: later 1.3.0 16: lifecycle 1.0.1 17: magrittr 2.0.2 18: mime 0.12 19: png 0.1-7 20: promises 1.2.0.1 21: r2d3 0.2.3 22: renv 0.15.4 23: rlang 1.0.2 24: sass 0.4.1 25: tools 4.1.1 26: withr 2.5.0 27: xtable 1.8-4 28: yaml 2.3.5