How to play local video in shiny app?(Windows) - r

I tried the follow code:
shinyUI(
fluidPage(
tags$video(id="video2", type = "video/mp4",src = "sample.mp4", controls = "controls")
)
)
shinyServer(function(input, output, session){})
But, it returns a blank page,
How should I do to play the video?

For anyone late to this question - it won't play in RStudio's 'Run App' environment - launch your app to the browser and it seems to work fine.

Related

unable to see output image in R shiny

i'm trying to show a logo in my Shiny app, but when i try to see i only can see a small icon, but not the image, this is my code:
library(shiny)
ui <- fluidPage(
mainPanel(
img(src='C:/Users/carlo239/image[![enter image description here][1]][1]/Capture2.jpg',
align = "right", height = '300px'),
### the rest of your code
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
And this is the issue, i tried to reload, but is not working,
I know that the image is ok, because if i click on Download i get the same image, but i'm unable to see in my outputs. THANKS !!
There are two ways:
Put the file in the www folder of your app (as suggested by #YBS). That is in most cases the recommended solution.
"Register" your folder as resource folder for your app (see below). However, that solution is intended to help package authors make resources available to the package's components. Also be aware that absolute paths can pose problems when you deploy your app.
library(shiny)
ui <- fluidPage(
mainPanel(
img(src='/foo/Capture2.jpg',
align = "right", height = '300px'),
### the rest of your code
)
)
server <- function(input, output, session) {
addResourcePath("foo", "C:/Users/wherever/your/file/may/be/located")
}
shinyApp(ui, server)

R shiny dynamically render audio [close]

I am working on a project, trying to render audio dynamically. That is, I can click a button and play a selected local audio.
I have read this post and tried zedii's trick. The problem remains still.
Well I build a test app as shown below.
library(shiny)
# test set ----
ui <- fluidPage(
textInput('my_music','path:',value="questionF"),
actionButton("ok", "Okay"),
uiOutput('my_audio')
# tags$audio(src = "questionF.mp3", type = "audio/mp3")
)
get_audio_tag <- function(filename) {
tags$audio(src = filename,
type = "audio/mp3",
controls = "controls")
}
server <- function(input, output, session){
# Render the audio player
observeEvent(input$ok, {
wav_name = input$my_music
# output$my_audio <-renderUI(get_audio_tag("questionF.mp3"))
output$my_audio <-renderUI(get_audio_tag(wav_name))
})
}
shinyApp(ui = ui, server = server)
When I click the button, the first song turns out okay. But the following ones seemed pretty hard to load, for my computer would freeze with the memory used by Rstudio rising.
Any thoughts will be appreciated.
updates:
I tried on different browsers. These codes would failed on Chrome but works fine on Microsoft edges.
Looks like a caching problem.
So now my question is how can I make the codes work on every platform using shiny/R?
My codes works on most browser other than Chrome. I think it's more like a Chrome's problem.

Shiny app radioButtons invisible in RStudio viewer pane

The RStudio (Version 1.2.1139 on macOS) viewer pane renders radioButtons (and FWIW, selected checkboxInputs) invisible. But these look and work fine in the browser, when 'Run External' is selected under the 'Run App' button. Below is a repro, and some screenshots.
Addendum: I note that shinyWidgets::prettyRadioButtons() resolves this issue immediately. Simply add library(shinyWidgets) at the top, and replace the call to radioButtons().
# Reproduce radioButtons invisibility in RStudio viewer pane
library(shiny)
ui <- fluidPage(
radioButtons("Dunit"
,"Dose Units"
,c("µg"="micrograms",
"mg"="milligrams",
"g"="grams")
,selected = "milligrams"
,inline = TRUE)
,checkboxGroupInput("Dper"
,NULL
,c("/m²"="perBSA",
"/kg"="perKg",
"abs"="absolute")
,selected = "perKg"
,inline = TRUE)
)
server <- function(input, output) {}
# Run the application
shinyApp(ui = ui, server = server)
In RStudio viewer pane:
In External browser:
This is a known issue in Chromium (the component powering RStudio's viewer) on MacOS. You can work around it by adding zoom: 1.0000001 or similar to the CSS that styles radio buttons for your Shiny app.
More info in this RStudio Github issue:
https://github.com/rstudio/rstudio/issues/3751

r shiny tags$video not showing video

I want to play an mp4 video in a shiny output. It plays fine on my computer when I double click on the file name. I copied the file to the www folder below the main app folder. I have tried variations on the following code.
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(debug = TRUE),
mainPanel(
"video test",
uiOutput('ozoneVideo'), id = "mainPanel")
)
server <- function(input, output, session) {
output$ozoneVideo <- renderUI({
h6("ozone video", tags$video(src = "MesaCountyOzone2017_07_10.mp4", type = "video/mp4", width = "1080px", height = "480px", controls = "controls", autoplay = NA))
})
}
shinyApp(ui = ui, server = server)
The web page that is generated shows the text elements (video test, ozone video) and horizontal bar with a video play button and the word "Error" with no explanation. No error appears in the javascript console.
When I add www/ to the filename, the javascript console has an error message "Failed to load resource: the server responded with a status of 404 (Not Found) and a url of http://127.0.0.1:4817/www/MesaCountyOzone2017_07_10.mp4
Any help clarifying this greatly appreciated!
Update: July 11, 2017.
I am now pretty sure this is a problem with Safari. I run the app with run external chosen. The web page that opens up in Safari has an error message in the video control section. If I copy the url and past to a Chrome web page, the video plays fine.
So my question is now what do I do to make this play in Safari???

Shiny open multiple browser tabs

In my Shiny app I want to open several URL's with a short delay between opening.
Here is some example code that works just fine when I run the app in my RStudio.
library(shiny)
URLs <- c("http://www.google.com", "http://www.stackoverflow.com")
ui <- fluidPage(
actionButton(
"click",
"Click here to open several browser tabs"
)
)
server <- function(input, output){
observeEvent(input$click, {
for (i in URLs){
browseURL(i)
Sys.sleep(1) #Short delay of 1 second
}
})
}
shinyApp(ui, server)
However, when I run this app on shinyapps.io, browseURL() doesn't work (as mentioned here).
Does anyone know how to open multiple browser tabs with a short delay between opening them, so that it also works when the app is deployed on shinyapps.io?
Would it be possible with R code or is JavaScript necessary?
This is a pretty old question, but answering in case others stumble upon while searching.
As mentioned in the reference you linked, I think you need to use some JS to accomplish this task. Below is an example of using the shinyjs package to define a shiny compatible browseURL function. Once we have the function defined we add a few lines to the ui and then call it in the server as js$browseURL().
Note that a pop-up blocker might block the effects of opening multiple tabs. Check your blocker settings if things don't seem to work.
library(shiny)
library(shinyjs)
# define js function for opening urls in new tab/window
js_code <- "
shinyjs.browseURL = function(url) {
window.open(url,'_blank');
}
"
URLs <- c("http://www.google.com", "http://www.stackoverflow.com")
ui <- fluidPage(
# set up shiny js to be able to call our browseURL function
useShinyjs(),
extendShinyjs(text = js_code, functions = 'browseURL'),
actionButton(
"click",
"Click here to open several browser tabs"
)
)
server <- function(input, output){
observeEvent(input$click, {
for (i in URLs){
js$browseURL(i)
Sys.sleep(1) #Short delay of 1 second
}
})
}
shinyApp(ui, server)

Resources