Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shiny Animation Issue #132

Open
lrmelt opened this issue Feb 15, 2016 · 9 comments · Fixed by #133
Open

Shiny Animation Issue #132

lrmelt opened this issue Feb 15, 2016 · 9 comments · Fixed by #133

Comments

@lrmelt
Copy link

lrmelt commented Feb 15, 2016

I am trying to create a bubbleMotion chart for a Shiny application using renderAnimint, but the animation is not working.

I can get the animation to work in R/Rstudio. However, when running that same code via Shiny App it plots, but the animation will not trigger.

server.R:

library(shiny)
library(animint)
traditional<-readRDS("data/traditional.rds")
shinyServer(function(input, output) {
  plotBubble <- reactive({
    ggplot()+ 
      geom_point(aes(pd2_plan_cost_pmpy, percent_contribution, colour=mci, showSelected=year, size=pmpy_rx_volume),data=traditional)+
      geom_text(aes(pd2_plan_cost_pmpy, percent_contribution, colour=mci, label=mci, showSelected=year),data=traditional)+
      continuous_scale("size","area",palette=function(x){scales:::rescale(sqrt(abs(x)), c(2,20), c(0,1))},breaks=10^(4:9))+
      theme(text=element_text(colour="white"),axis.text=element_text(color="white"),plot.background=element_rect(fill = "#3475b4"),panel.background = element_rect(fill = "#3475b4"),legend.position="none",panel.grid.minor = element_line(colour="white", size=0.5)) +
      theme_animint(height = 600, width = 900)  
  })
  output$animint <- renderAnimint({ 
    list(plot1 = plotBubble(),
         time = list(variable = "year", ms = 2000),
         duration=list(year=4))
  })  
})

ui.R

library(shiny)
library(animint)

shinyUI(fluidPage(  
  titlePanel("Drug Trend"), 
  br(),  
  animintOutput("animint")  
))

Here is the plot within the Shiny app called from a URL:
animintbubbleplot

Clicking "Play" does not do anything...however, it properly runs through 4 years of data in R/RStudio with this same code.

Please advise.

Thanks,
Logan

@tdhock tdhock mentioned this issue Feb 16, 2016
@tdhock
Copy link
Owner

tdhock commented Feb 16, 2016

Thanks for your interest in animint, and thanks for your detailed bug report.

I have created a unit test in #133 that captures your problem and I will ask my collaborators to look into it.

@lrmelt
Copy link
Author

lrmelt commented Feb 17, 2016

Great, thank you @tdhock!

Let me know if there is anything I can do to assist.

@lrmelt
Copy link
Author

lrmelt commented Feb 21, 2016

@tdhock any luck in solving this?

@tdhock
Copy link
Owner

tdhock commented Feb 22, 2016

My collaborators and I have not yet had time to figure it out. If you have time, look at the JS errors shown in #133 and see if you can fix the code in animint.js --seems to have something to do with our use of selectize widgets. We would be more than willing to accept a Pull Request that fixes this!

Also you may want to try a workaround: disabling selectize widgets https://github.com/tdhock/animint/wiki/Advanced-features-present-animint-but-not-in-ggplot2#use-selectize-option-to-showhide-selector-widgets Can you try selectize=list(year=FALSE) e.g.

  output$animint <- renderAnimint({ 
    list(plot1 = plotBubble(),
         selectize=list(selectize=list(year=FALSE),
         time = list(variable = "year", ms = 2000),
         duration=list(year=4))
  })  

Not sure if that will help but it is worth a try I think.

@lrmelt
Copy link
Author

lrmelt commented Feb 23, 2016

The selectize suggestion did not work....I am playing with animint.js now.

@tdhock
Copy link
Owner

tdhock commented Mar 1, 2016

Hey @lrmelt I fixed your problem in #133

try installing that branch to see if it works for you

devtools::install_github("tdhock/animint@animation-fix")

@lrmelt
Copy link
Author

lrmelt commented Mar 4, 2016

Thanks for working on this!

I installed the current master and now the motion does not even work in RStudio.

I cannot use devtools::install_github("tdhock/animint@animation-fix") as I am behind a firewall...so I have to use devtools::install_local. Is there a different source I should use other than animint-master.zip?

@tdhock
Copy link
Owner

tdhock commented Mar 4, 2016

too bad it is not working for you.

can you post the specific data set and code that you used?

and your session info?

thocking@silene:~/R/animint(master)$ R --vanilla

R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(animint)
Loading required package: ggplot2
Loading required package: proto
> devtools::session_info()
Session info -------------------------------------------------------------------
 setting  value                       
 version  R version 3.2.3 (2015-12-10)
 system   x86_64, linux-gnu           
 ui       X11                         
 language en_CA:en                    
 collate  en_CA.UTF-8                 
 tz       <NA>                        
 date     2016-03-04                  

Packages -----------------------------------------------------------------------
 package    * version    date       source                         
 animint    * 2016.03.01 2016-03-02 Github (tdhock/animint@d375e34)
 colorspace   1.2-6      2015-03-11 CRAN (R 3.2.3)                 
 devtools     1.10.0     2016-01-23 CRAN (R 3.2.3)                 
 digest       0.6.9      2016-01-08 CRAN (R 3.2.3)                 
 ggplot2    * 1.0.1      2016-02-15 Github (tdhock/ggplot2@a8b06dd)
 gtable       0.1.2      2012-12-05 CRAN (R 3.0.2)                 
 magrittr     1.5        2014-11-22 CRAN (R 3.2.0)                 
 MASS         7.3-45     2015-11-10 CRAN (R 3.2.3)                 
 memoise      1.0.0      2016-01-29 CRAN (R 3.2.3)                 
 munsell      0.4.3      2016-02-13 CRAN (R 3.2.3)                 
 plyr         1.8.3      2015-06-12 CRAN (R 3.2.3)                 
 proto      * 1.0.0      2015-06-17 Github (hadley/proto@a4d8fe1)  
 Rcpp         0.12.3     2016-01-10 CRAN (R 3.2.3)                 
 reshape2     1.4.1      2014-12-06 CRAN (R 3.2.3)                 
 scales       0.2.5      2016-03-02 Github (hadley/scales@2c3edf4) 
 stringi      1.0-1      2015-10-22 CRAN (R 3.2.3)                 
 stringr      1.0.0      2015-04-30 CRAN (R 3.2.3)                 
> 

@tdhock tdhock reopened this Mar 4, 2016
@lrmelt
Copy link
Author

lrmelt commented Mar 4, 2016

Sure.

animint_issue.xlsx

server.R

library(shiny)
library(animint)
data<-readRDS("data/data.rds")

shinyServer(function(input, output) {
  plotBubble <- reactive({
    ggplot()+ 
      geom_point(aes(Plan.Cost.PMPY, X..Contribution , colour=MCI, showSelected=Year, size=Rx.Volume.PMPY),data=data)+
      geom_text(aes(Plan.Cost.PMPY, X..Contribution , colour=MCI, label=MCI, showSelected=Year),data=data)+
      continuous_scale("size","area",palette=function(x){scales:::rescale(sqrt(abs(x)), c(2,20), c(0,1))},breaks=10^(4:9))+
      theme(text=element_text(colour="white"),axis.text=element_text(color="white"),plot.background=element_rect(fill = "#3475b4"),panel.background = element_rect(fill = "#3475b4"),legend.position="none",panel.grid.minor = element_line(colour="white", size=0.5)) +
      theme_animint(height = 600, width = 900)  
  })
  output$animint <- renderAnimint({ 
    list(plot1 = plotBubble(),
         time = list(variable = "Year", ms = 2000),
         duration=list(Year=4))
  })  
})

ui.R

library(shiny)
library(animint)
shinyUI(fluidPage(  
  titlePanel("Drug Trend"), 
  br(),  
  animintOutput("animint")  
))
> devtools::session_info()
Session info------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.1.1 (2014-07-10)
 system   x86_64, linux-gnu           
 ui       RStudio (0.98.1056)         
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       <NA>                        

Packages----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 package      * version  date       source        
 animation    * 2.3      2014-07-25 CRAN (R 3.1.1)
 animint      * 2016.3.1 2016-03-04 local (/@)    
 assertthat     0.1      2013-12-06 CRAN (R 3.1.1)
 base64enc      0.1.2    2014-06-26 CRAN (R 3.1.1)
 chron          2.3.45   2014-02-11 CRAN (R 3.1.1)
 codetools      0.2.8    2011-02-15 CRAN (R 3.1.1)
 colorspace     1.2.4    2013-09-30 CRAN (R 3.1.1)
 data.table   * 1.9.6    2015-09-19 CRAN (R 3.1.1)
 DBI            0.3.1    2014-09-24 CRAN (R 3.1.1)
 devtools       1.6.1    2014-10-07 CRAN (R 3.1.1)
 digest         0.6.4    2013-12-03 CRAN (R 3.1.1)
 doParallel   * 1.0.8    2014-02-28 CRAN (R 3.1.1)
 dplyr        * 0.4.1    2015-01-14 CRAN (R 3.1.1)
 DT           * 0.1.39   2015-10-07 local         
 dygraphs     * 0.5      2015-10-20 CRAN (R 3.1.1)
 foreach      * 1.4.2    2014-04-11 CRAN (R 3.1.1)
 ggplot2      * 1.0.1    2016-02-15 local (/@)    
 googleVis    * 0.5.8    2015-01-22 CRAN (R 3.1.1)
 gridExtra    * 2.0.0    2015-07-14 CRAN (R 3.1.1)
 gtable       * 0.1.2    2012-12-05 CRAN (R 3.1.1)
 hexbin       * 1.27.1   2015-08-19 local (/@)    
 htmltools      0.3      2015-12-29 CRAN (R 3.1.1)
 htmlwidgets    0.4      2015-05-28 local         
 httpuv         1.3.3    2015-08-04 local (/@)    
 iterators    * 1.0.7    2014-04-11 CRAN (R 3.1.1)
 jsonlite       0.9.13   2014-10-21 CRAN (R 3.1.1)
 labeling       0.3      2014-08-23 CRAN (R 3.1.1)
 lattice        0.20.29  2014-04-04 CRAN (R 3.1.1)
 lazyeval       0.1.9    2014-10-01 CRAN (R 3.1.1)
 lubridate    * 1.3.3    2013-12-31 CRAN (R 3.1.1)
 magrittr       1.0.1    2014-05-15 CRAN (R 3.1.1)
 MASS           7.3.35   2014-09-30 CRAN (R 3.1.1)
 memoise        0.2.1    2014-04-22 CRAN (R 3.1.1)
 mime           0.3      2015-03-29 CRAN (R 3.1.1)
 munsell        0.4.2    2013-07-11 CRAN (R 3.1.1)
 networkD3    * 0.2.8    2015-12-31 CRAN (R 3.1.1)
 NLP          * 0.1.8    2015-07-03 CRAN (R 3.1.1)
 plyr           1.8.1    2014-02-26 CRAN (R 3.1.1)
 proto        * 0.3.10   2012-12-22 CRAN (R 3.1.1)
 R6             2.0      2014-08-19 CRAN (R 3.1.1)
 RColorBrewer * 1.1.2    2014-12-07 CRAN (R 3.1.1)
 Rcpp           0.12.3   2016-01-10 CRAN (R 3.1.1)
 reshape2     * 1.4      2014-04-23 CRAN (R 3.1.1)
 RJSONIO      * 1.3.0    2014-07-28 local (/@)    
 rstudioapi     0.1      2014-03-27 CRAN (R 3.1.1)
 scales         0.2.4    2014-04-22 CRAN (R 3.1.1)
 sendmailR    * 1.2.1    2014-09-21 CRAN (R 3.1.1)
 servr        * 0.1      2013-10-05 CRAN (R 3.1.1)
 shiny        * 0.13.0   2016-01-12 CRAN (R 3.1.1)
 shinyBS      * 0.61     2015-03-31 CRAN (R 3.1.1)
 slam           0.1.32   2014-04-02 CRAN (R 3.1.1)
 SnowballC    * 0.5.1    2014-08-09 CRAN (R 3.1.1)
 stringi        0.4.1    2014-12-14 CRAN (R 3.1.1)
 stringr      * 1.0.0    2015-04-30 CRAN (R 3.1.1)
 tm           * 0.6.1    2015-05-07 CRAN (R 3.1.1)
 wordcloud    * 2.5      2014-06-13 CRAN (R 3.1.1)
 xtable         1.7.4    2014-09-12 CRAN (R 3.1.1)
 xts          * 0.9.7    2014-01-02 CRAN (R 3.1.1)
 zoo          * 1.7.11   2014-02-27 CRAN (R 3.1.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants