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
软件包。