Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shiny 如何创建和显示动画GIF的光泽?_Shiny_Gif_Gganimate - Fatal编程技术网

Shiny 如何创建和显示动画GIF的光泽?

Shiny 如何创建和显示动画GIF的光泽?,shiny,gif,gganimate,Shiny,Gif,Gganimate,我可以将保存的文件作为图像加载,但无法使用gganimate直接加载。了解渲染GIF的其他方法会很好,但是知道如何渲染gganimate确实可以解决我的问题 library(gapminder) library(ggplot2) library(shiny) library(gganimate) theme_set(theme_bw()) ui <- basicPage( plotOutput("plot1") ) server <- function(input, ou

我可以将保存的文件作为图像加载,但无法使用
gganimate
直接加载。了解渲染GIF的其他方法会很好,但是知道如何渲染
gganimate
确实可以解决我的问题

library(gapminder)
library(ggplot2)
library(shiny)
library(gganimate)
theme_set(theme_bw())

ui <- basicPage(
    plotOutput("plot1")
)

server <- function(input, output) {
    output$plot1 <- renderPlot({
        p = ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
  geom_point() +
  scale_x_log10()

       gg_animate(p)

    })

}

shinyApp(ui, server)
库(gapminder)
图书馆(GG2)
图书馆(闪亮)
库(gganimate)
theme_set(theme_bw())

ui我在处理同一个问题,只找到了你的问题,没有找到答案。。。但是你的措辞提醒我,
renderPlot
很挑剔:

它不会将任何图像文件发送到浏览器——图像必须由使用R的图形输出设备系统的代码生成。创建图像的其他方法无法通过
renderPlot()
发送。。。这些情况下的解决方案是
renderImage()
函数

修改该文章中的代码将提供以下内容:

library(gapminder)
library(ggplot2)
library(shiny)
library(gganimate)
theme_set(theme_bw())

ui <- basicPage(
    imageOutput("plot1"))

server <- function(input, output) {
    output$plot1 <- renderImage({
    # A temp file to save the output.
    # This file will be removed later by renderImage
    outfile <- tempfile(fileext='.gif')

    # now make the animation
    p = ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, 
      color = continent, frame = year)) + geom_point() + scale_x_log10()

    gg_animate(p,"outfile.gif")

    # Return a list containing the filename
     list(src = "outfile.gif",
         contentType = 'image/gif'
         # width = 400,
         # height = 300,
         # alt = "This is alternate text"
         )}, deleteFile = TRUE)}

shinyApp(ui, server)
库(gapminder)
图书馆(GG2)
图书馆(闪亮)
库(gganimate)
theme_set(theme_bw())

ui现在有了一个新的突破性版本的
gganimate
,@kt.leap的答案不受欢迎。以下是我使用新的
gganimate
时的效果:

library(gapminder)
library(ggplot2)
library(shiny)
library(gganimate)
theme_set(theme_bw())

ui <- basicPage(
    imageOutput("plot1"))

server <- function(input, output) {
    output$plot1 <- renderImage({
    # A temp file to save the output.
    # This file will be removed later by renderImage
    outfile <- tempfile(fileext='.gif')

    # now make the animation
    p = ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, 
      color = continent)) + geom_point() + scale_x_log10() +
      transition_time(year) # New

    anim_save("outfile.gif", animate(p)) # New

    # Return a list containing the filename
     list(src = "outfile.gif",
         contentType = 'image/gif'
         # width = 400,
         # height = 300,
         # alt = "This is alternate text"
         )}, deleteFile = TRUE)}

shinyApp(ui, server)
库(gapminder)
图书馆(GG2)
图书馆(闪亮)
库(gganimate)
theme_set(theme_bw())

对不起,耽误了你回来。生活妨碍了我们。您的解决方案需要将文件保存到磁盘。我在问题中已经提到,我可以加载保存的文件,这样就不会增加太多。据我所知,它不会将文件保存到磁盘。它是一个由
renderImage
使用的文件,与
renderPlot
框架相反。因此,它将直接渲染
gganimate
,无需做任何进一步的操作,但它使用
renderImage
进行渲染。我收到一条错误消息:“gg对象的动画不受支持”@jlp此代码仍然适用于我。检查您是否已更新所有内容,包括
gifski
软件包。