Installing ImageMagick tools on glimmer

1,033 views
Skip to first unread message

Stéphane Laurent

unread,
May 29, 2013, 1:34:10 PM5/29/13
to shiny-...@googlegroups.com
Hello, 

 Is it possible to install ImageMagick on a personal glimmer account ? 
I would like to use the animation package with Shiny.

Winston Chang

unread,
May 29, 2013, 3:37:28 PM5/29/13
to shiny-...@googlegroups.com
Hi Stephane - I've installed imagemagick on glimmer and spark.

-Winston


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Stéphane Laurent

unread,
May 29, 2013, 4:57:46 PM5/29/13
to shiny-...@googlegroups.com
Thanks !
My next exercise: trying to create a video and to embed it into the html rendering :)

Stéphane Laurent

unread,
May 30, 2013, 10:33:13 AM5/30/13
to shiny-...@googlegroups.com
I have done several naive attempts, unsuccessful.

Would we need a `renderVideo()` function similar to `renderImage()` or is it possible to embed a video without additional function ? 

Below is one of my naive attempts. I expected to be able to modify myself the `renderImage()` and `imageOutput` functions, but I'm really too much ignorant about html.

``` 
# server.R 
library(animation)
shinyServer(function(input, output) {
  output$video <- renderImage({
    n <- input$n
    filename <-  tempfile(fileext='.webm')
    videoname <- basename(filename)
    outdir <- dirname(filename)
    saveVideo({
      for (i in 1:n) {
        curve(dnorm(x), from = -4, to = 4)
        set.seed(666)
        simulation <- rnorm(i)
        points(x = simulation, y = rep(0, i), col = "red", pch = 19)
      }
    }, video.name = videoname, outdir = outdir)
    list(src=filename,
         alt="This is alternate text",
         contentType='video/webm; codecs="vp8.0, vorbis"'
         )
  }, deleteFile=FALSE)
})
``` 

``` 
# ui.R
shinyUI(pageWithSidebar(
  headerPanel("Video embedding"),
  sidebarPanel(
    numericInput("n", label="n", value=10)
  ),
  mainPanel(
    h3("Video"),
    imageOutput("video")
  )
))
``` 

Joe Cheng

unread,
May 30, 2013, 12:42:20 PM5/30/13
to shiny-...@googlegroups.com
I think you want to write the video file into a subdirectory of your app called "www" (if it doesn't have one, create one). The name of the subdirectory MUST be "www".

Then use renderUI instead of renderImage. Your renderUI block should return a video tag like so:

tags$video(src=filename, width="640", height="480")

The filename is the bare filename of the video file, i.e. do NOT include "www".

Then in ui.R use uiOutput or htmlOutput instead of imageOutput.


--

Stéphane Laurent

unread,
May 30, 2013, 1:15:48 PM5/30/13
to shiny-...@googlegroups.com
Thank you very much - nice ! 

However the code below works well with my local server localhost:8100 but it does not work in glimmer (for me) : http://glimmer.rstudio.com/stla/testVideo/

I use the webm format video for Google Chrome. This link provides useful information about some possible difficulties with video embedding : http://stackoverflow.com/questions/16487767/knitr-mp4-movie-embedding-does-not-work-on-windows-xp


## server.R
library(animation)
shinyServer(function(input, output) {
  output$video <- renderUI({
    n <- input$n
    videoname <- "gaussian.webm"
    outdir <- paste0(getwd(),"/www")
    saveVideo({
      for (i in 1:n) {
        curve(dnorm(x), from = -4, to = 4)
        set.seed(666)
        simulation <- rnorm(i)
        points(x = simulation, y = rep(0, i), col = "red", pch = 19)
      }
    }, video.name = videoname, outdir = outdir)
    tags$video(src=videoname, width="640", height="480", type='video/webm; codecs="vp8.0, vorbis"', controls="controls")
  })
})

## ui .R
shinyUI(pageWithSidebar(
  headerPanel("Video embedding"),
#
  sidebarPanel(
    numericInput("n", label="n", value=10)
  ),
  mainPanel(
    h3("Video"),
    uiOutput("video")
  )
))

Stéphane Laurent

unread,
May 30, 2013, 1:17:46 PM5/30/13
to shiny-...@googlegroups.com
I have just seen that there's no video created in my www subfolder in glimmer. Maybe I misspecify the path.

Ramnath Vaidyanathan

unread,
May 30, 2013, 1:28:23 PM5/30/13
to shiny-...@googlegroups.com
I think you should remove getwd() from this line

paste0(getwd(),"/www")

Stéphane Laurent

unread,
May 30, 2013, 1:30:05 PM5/30/13
to shiny-...@googlegroups.com
Oh I understand !!

That cannot work : the ffmpeg command is not recognized in the Shell. If ffmpeg (http://www.ffmpeg.org/) is not installed, the video cannot be created.

On Windows I have installed a distribution of ImageMagick containing ffmpeg. 

Stéphane Laurent

unread,
May 30, 2013, 1:32:15 PM5/30/13
to shiny-...@googlegroups.com
Hello Ramnath. I have try to write explictely the path, but that does not work. ffmpeg is missing :)

Yihui Xie

unread,
May 30, 2013, 2:10:23 PM5/30/13
to shiny-...@googlegroups.com
There is no ffmpeg on glimmer:

$ ffmpeg
The program 'ffmpeg' is currently not installed. To run 'ffmpeg'
please ask your administrator to install the package 'libav-tools'

With ImageMagick, you can also create a video using `convert`, but my
gut feeling is that ffmpeg may be better for this purpose.

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA

Stéphane Laurent

unread,
May 30, 2013, 2:12:58 PM5/30/13
to shiny-...@googlegroups.com
Dear Joe,

 How to include several tags$video in renderUI() ? As shown in the wikipedia example we must include the video in several formats if we want multi-browsers compatibility. But they must be included in a unique <video>...</video> container. 

Joe Cheng

unread,
May 30, 2013, 2:51:02 PM5/30/13
to shiny-...@googlegroups.com
<video poster="movie.jpg" controls>
        <source src="movie.webm" type='video/webm; codecs="vp8.0, vorbis"'/>
        <source src="movie.ogg" type='video/ogg; codecs="theora, vorbis"'/>
        <source src="movie.mp4" type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'/>
        <p>This is fallback content</p>
</video>

translates to:

tags$video(poster="movie.jpg", controls="controls",
  tags$source(src="movie.webm", type='video/webm; codecs="vp8.0, vorbis"'),
  tags$source(src="movie.ogg", type='video/ogg; codecs="theora, vorbis"'),
  tags$source(src="movie.mp4", type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'),
  tags$p("This is fallback content")
)

Actually with that much code you might want to do this:

withTags(
  video(poster="movie.jpg", controls="controls",
    source(src="movie.webm", type='video/webm; codecs="vp8.0, vorbis"'),
    source(src="movie.ogg", type='video/ogg; codecs="theora, vorbis"'),
    source(src="movie.mp4", type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'),
    p("This is fallback content")
  )
)

I'll ask Winston to install ffmpeg on our servers.

Stéphane Laurent

unread,
May 30, 2013, 3:06:30 PM5/30/13
to shiny-...@googlegroups.com
Thank you !

@Yihui, as you see, it would be nice to generate several video formats with only one call to saveVideo().

Winston Chang

unread,
May 30, 2013, 3:13:09 PM5/30/13
to shiny-...@googlegroups.com
I've installed ffmpeg.

It looks ffmpeg was forked into two projects, ffmpeg and libav. The latter is used on Debian/Ubuntu, and when you run 'ffmpeg' on Ubuntu, it gives the following:
ffmpeg version 0.8.6-4:0.8.6-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav developers
  built on Apr  2 2013 17:02:36 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.

So ffmpeg will work, but it suggests that you use avconv instead. I believe they both point to the same binary, so it should work either way for now.

-Winston



On Thu, May 30, 2013 at 2:06 PM, Stéphane Laurent <lauren...@yahoo.fr> wrote:
Thank you !

@Yihui, as you see, it would be nice to generate several video formats with only one call to saveVideo().

--

Stéphane Laurent

unread,
May 30, 2013, 3:28:12 PM5/30/13
to shiny-...@googlegroups.com
Thank you Winston ! 

Here is the version with avconv :  http://glimmer.rstudio.com/stla/testVideoavconv/ (with the webm format => Chrome only)

The code of server.R :

# server R
library(animation)
shinyServer(function(input, output) {
  output$video <- renderUI({
    n <- input$n
    videoname <- "gaussian.webm"
    outdir <- "~/ShinyApps/testVideoavconv/www"
    saveVideo({
      for (i in 1:n) {
        curve(dnorm(x), from = -4, to = 4)
        set.seed(666)
        simulation <- rnorm(i)
        points(x = simulation, y = rep(0, i), col = "red", pch = 19)
      }
    }, video.name = videoname, outdir = outdir, ffmpeg="avconv")
    tags$video(src=videoname, width="640", height="480", type='video/webm; codecs="vp8.0, vorbis"', controls="controls")
  })
})

Joe Cheng

unread,
May 31, 2013, 2:13:59 AM5/31/13
to shiny-...@googlegroups.com
This is very cool! I didn't realize the animate package was this easy to use.

Another option for (very simple) animations based off a single scalar value is to use sliderInput, with the animate parameter set to TRUE, which adds a very small Play button at the right of the slider. See ?sliderInput for more details.

Stéphane Laurent

unread,
May 31, 2013, 2:42:07 AM5/31/13
to shiny-...@googlegroups.com
Yes I know for the slider. I have already tried it - see the link I've given here  https://github.com/ramnathv/rCharts/issues/87 

But the result is not as fluid as a video.

Andreas Tonio Liebrand

unread,
Feb 9, 2015, 4:39:40 PM2/9/15
to shiny-...@googlegroups.com
Hi Stéphane,
great work! It looks amazing.
I have one question:
How did u resolve the error that the video is not saved in the subfolder "www"?
"~/ShinyApps/..../www" did not work for me. 
I used ur following code.
But the file is not saved correctly.

Thank you for your help!
Andreas

# server.R
library(animation)
shinyServer(function(input, output) {
  output$video <- renderUI({
    n <- input$n
    videoname <- "gaussian.webm"
    outdir <- "~/ShinyApps/Animation/www"
    saveVideo({
      for (i in 1:n) {
        curve(dnorm(x), from = -4, to = 4)
        set.seed(666)
        simulation <- rnorm(i)
        points(x = simulation, y = rep(0, i), col = "red", pch = 19)
      }
    }, video.name = videoname, outdir = outdir, ffmpeg="avconv")
    tags$video(src=videoname, width="640", height="480", type='video/webm; codecs="vp8.0, vorbis"', controls="controls")
  })
})

## ui .R
shinyUI(pageWithSidebar(
  headerPanel("Video embedding"),
  #
  sidebarPanel(
    numericInput("n", label="n", value=10)
  ),
  mainPanel(
    h3("Video"),
    uiOutput("video")
  )
))


laurent stephane

unread,
Feb 9, 2015, 6:37:10 PM2/9/15
to Andreas Tonio Liebrand, shiny-...@googlegroups.com
Hello Andreas,
This code works for me. Maybe you need to create an empty www folder before ?


Thank you Winston ! 

Here is the version with avconv :  http://glimmer.rstudio.com/ stla/testVideoavconv/ (with the webm format => Chrome only)

The code of server.R :

# server R
library(animation)
shinyServer(function(input, output) {
  output$video <- renderUI({
    n <- input$n
    videoname <- "gaussian.webm"
    outdir <- "~/ShinyApps/testVideoavconv/ www"
    saveVideo({
      for (i in 1:n) {
        curve(dnorm(x), from = -4, to = 4)
        set.seed(666)
        simulation <- rnorm(i)
        points(x = simulation, y = rep(0, i), col = "red", pch = 19)
      }
    }, video.name = videoname, outdir = outdir, ffmpeg="avconv")
    tags$video(src=videoname, width="640", height="480", type='video/webm; codecs="vp8.0, vorbis"', controls="controls")
  })
})

Le jeudi 30 mai 2013 21:13:09 UTC+2, Winston Chang a écrit :
I've installed ffmpeg.

It looks ffmpeg was forked into two projects, ffmpeg and libav. The latter is used on Debian/Ubuntu, and when you run 'ffmpeg' on Ubuntu, it gives the following:
ffmpeg version 0.8.6-4:0.8.6-0ubuntu0.12.04. 1, Copyright (c) 2000-2013 the Libav developers
  built on Apr  2 2013 17:02:36 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.

So ffmpeg will work, but it suggests that you use avconv instead. I believe they both point to the same binary, so it should work either way for now.

-Winston



On Thu, May 30, 2013 at 2:06 PM, Stéphane Laurent <lauren...@yahoo.fr> wrote:
Thank you !

@Yihui, as you see, it would be nice to generate several video formats with only one call to saveVideo().
--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups. com.
For more options, visit https://groups.google.com/ groups/opt_out.
 
 

--
You received this message because you are subscribed to a topic in the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/shiny-discuss/QjketNq6UII/unsubscribe.
To unsubscribe from this group and all its topics, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/603ff88c-38d5-4790-8559-7086826667ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


laurent stephane

unread,
Feb 9, 2015, 6:40:34 PM2/9/15
to Andreas Tonio Liebrand, shiny-...@googlegroups.com
I see, you are using animation 2.3 whereas I use 2.2 :

 o the animation option `outdir` in ani.options() was removed because it
  was confusing to many users that the output is in a temporary directory by
  default; now all files are written relative to the current working
  directory (#31)
http://cran.r-project.org/web/packages/animation/NEWS

Andreas Tonio Liebrand

unread,
Feb 11, 2015, 3:16:10 PM2/11/15
to shiny-...@googlegroups.com, a.lie...@stud.uni-goettingen.de, lauren...@yahoo.fr
Thanks. setwd() helped me to solve it then!
Reply all
Reply to author
Forward
0 new messages