1

I was wondering, is it possible to use the HTML() function in R shiny to excute an html5 code that will allow me to access my webcam from my browser (similar to what was proposed in this topic: Access camera from a browser)

Here is my example:

library(shiny)

ui <- fluidPage(
  titlePanel(title = "Test Cam App",windowTitle = "Test Cam App"),

  wellPanel(uiOutput("video"))

)



server <- function(input, output, session) {

  output$video <- renderUI(HTML("
       <video autoplay></video>
       <script>
       var onFailSoHard = function(e) {
       console.log('Reeeejected!', e);
       };
       navigator.getUserMedia({video: true, audio: true}, function(localMediaStream) {
       var video = document.querySelector('video');
       video.src = window.URL.createObjectURL(localMediaStream);
       video.onloadedmetadata = function(e) {
       };
       }, onFailSoHard);
       </script>
       "))

}

shinyApp(ui = ui, server = server)

When I run the app on a browser (chrome) I get the message to unable my camera, and I also get the camera icon, however the video input is not displayed:

Screenshot of the result

  • Did you try it? Where exactly did you get stuck? What "html5 code" are you trying to execute? Shiny shouldn't prevent you from doing anything you can do with a different web server. – MrFlick Aug 22 '19 at 15:36
  • Yes, I tried one of the responses of the topic that I linked, but I don't know how to display the camera input into the UI of shiny. – HENNI Mohamed Aug 22 '19 at 18:27
  • Well, your question should show a minimal [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) showing your code attempts and describing exactly what didn't work with your code (including error messages and such) – MrFlick Aug 22 '19 at 18:57
  • Yes, I added my example, however there is no error message, it is just that the camera input is not displaying, maybe I did not include correctly the output option. I also searched for an example on the web but I did not found a solution. – HENNI Mohamed Aug 23 '19 at 07:41

0 Answers0