From cf9197238ef121557c5fec2a40ef7e6b30ab94c9 Mon Sep 17 00:00:00 2001 From: JohnCoene Date: Sat, 23 Mar 2019 17:29:36 +0100 Subject: [PATCH 1/2] no need to pass session anymore --- DESCRIPTION | 2 +- R/anim.R | 12 ++++++------ man/addHoverAnim.Rd | 4 +--- man/addScrollAnim.Rd | 4 +--- man/startAnim.Rd | 4 +--- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f81d73f..226bac5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: shinyanimate Type: Package Title: Animation for 'shiny' Elements -Version: 0.3.0 +Version: 0.3.0 Author: Swechhya Bista Maintainer: Swechhya Bista Description: An extension of 'animate.css' that allows user to easily add animations to any UI element in 'shiny' app using the elements id. diff --git a/R/anim.R b/R/anim.R index d113959..353a356 100644 --- a/R/anim.R +++ b/R/anim.R @@ -23,7 +23,6 @@ withAnim <- function(){ #' #' Start an animation of the UI element. #' @export -#' @param session The session object passed to function given to shinyServer. #' @param id the id of the UI element for which you want to add animation. #' @param type The type of animation to use, valid values correspond to the types in \url{https://daneden.github.io/animate.css/} #' @examples @@ -44,7 +43,8 @@ withAnim <- function(){ #'} #'@seealso \code{\link{withAnim}} #' -startAnim <- function(session, id, type = NULL){ +startAnim <- function(id, type = NULL){ + session <- shiny::getDefaultReactiveDomain() session$sendCustomMessage( type = "addClass", message = list(ele = id, name = type)) @@ -52,7 +52,6 @@ startAnim <- function(session, id, type = NULL){ #' Add animation on mouse hover for UI element. #' @export -#' @param session The session object passed to function given to shinyServer. #' @param id the id of the UI element for which you want animation on mouse hover. #' @param type The type of animation to use, valid values correspond to the types in \url{https://daneden.github.io/animate.css/} #' @examples @@ -70,7 +69,8 @@ startAnim <- function(session, id, type = NULL){ #'} #'@seealso \code{\link{withAnim}} #' -addHoverAnim <- function(session, id, type = NULL) { +addHoverAnim <- function(id, type = NULL) { + session <- shiny::getDefaultReactiveDomain() session$sendCustomMessage( type = "addClassHover", message = list(ele = id, name = type)) @@ -78,7 +78,6 @@ addHoverAnim <- function(session, id, type = NULL) { #' Add animation on scroll for UI element. #' @export -#' @param session The session object passed to function given to shinyServer. #' @param id the id of the UI element for which you want animation on scroll. #' @param type The type of animation to use, valid values correspond to the types in \url{https://daneden.github.io/animate.css/} #' @examples @@ -103,7 +102,8 @@ addHoverAnim <- function(session, id, type = NULL) { #'} #'@seealso \code{\link{withAnim}} #' -addScrollAnim <- function(session, id, type = NULL) { +addScrollAnim <- function(id, type = NULL) { + session <- shiny::getDefaultReactiveDomain() session$sendCustomMessage( type = "addClassScroll", message = list(ele = id, name = type)) diff --git a/man/addHoverAnim.Rd b/man/addHoverAnim.Rd index 3f8ceb1..97b019e 100644 --- a/man/addHoverAnim.Rd +++ b/man/addHoverAnim.Rd @@ -4,11 +4,9 @@ \alias{addHoverAnim} \title{Add animation on mouse hover for UI element.} \usage{ -addHoverAnim(session, id, type = NULL) +addHoverAnim(id, type = NULL) } \arguments{ -\item{session}{The session object passed to function given to shinyServer.} - \item{id}{the id of the UI element for which you want animation on mouse hover.} \item{type}{The type of animation to use, valid values correspond to the types in \url{https://daneden.github.io/animate.css/}} diff --git a/man/addScrollAnim.Rd b/man/addScrollAnim.Rd index fa97473..f7ba39f 100644 --- a/man/addScrollAnim.Rd +++ b/man/addScrollAnim.Rd @@ -4,11 +4,9 @@ \alias{addScrollAnim} \title{Add animation on scroll for UI element.} \usage{ -addScrollAnim(session, id, type = NULL) +addScrollAnim(id, type = NULL) } \arguments{ -\item{session}{The session object passed to function given to shinyServer.} - \item{id}{the id of the UI element for which you want animation on scroll.} \item{type}{The type of animation to use, valid values correspond to the types in \url{https://daneden.github.io/animate.css/}} diff --git a/man/startAnim.Rd b/man/startAnim.Rd index 7bdb8b1..720c209 100644 --- a/man/startAnim.Rd +++ b/man/startAnim.Rd @@ -4,11 +4,9 @@ \alias{startAnim} \title{Start an animation} \usage{ -startAnim(session, id, type = NULL) +startAnim(id, type = NULL) } \arguments{ -\item{session}{The session object passed to function given to shinyServer.} - \item{id}{the id of the UI element for which you want to add animation.} \item{type}{The type of animation to use, valid values correspond to the types in \url{https://daneden.github.io/animate.css/}} From 39e97d637f4333f412102df7c33a974b26c4a058 Mon Sep 17 00:00:00 2001 From: JohnCoene Date: Sat, 23 Mar 2019 17:31:05 +0100 Subject: [PATCH 2/2] documentation updated --- R/anim.R | 12 ++++++------ man/addHoverAnim.Rd | 4 ++-- man/addScrollAnim.Rd | 4 ++-- man/startAnim.Rd | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/R/anim.R b/R/anim.R index 353a356..3d0d798 100644 --- a/R/anim.R +++ b/R/anim.R @@ -36,10 +36,10 @@ withAnim <- function(){ #') #'server <- function(input, output, session){ #' observeEvent(input$button,{ -#' startAnim(session, 'title', 'bounce') +#' startAnim('title', 'bounce') #' }) #'} -#'shinyApp(ui, server) +#'if(interactive()) shinyApp(ui, server) #'} #'@seealso \code{\link{withAnim}} #' @@ -63,9 +63,9 @@ startAnim <- function(id, type = NULL){ #' tags$div(id = 'title', h1('HOVER ON ME')) #' ) #' server <- function(input, output, session){ -#' observe(addHoverAnim(session, 'title', 'bounce')) +#' observe(addHoverAnim('title', 'bounce')) #' } -#' shinyApp(ui, server) +#'if(interactive()) shinyApp(ui, server) #'} #'@seealso \code{\link{withAnim}} #' @@ -96,9 +96,9 @@ addHoverAnim <- function(id, type = NULL) { #' tags$div(id = 'title', h1('I ANIMATE ON SCROLL')) #' ) #' server <- function(input, output, session){ -#' observe(addScrollAnim(session, 'title', 'bounce')) +#' observe(addScrollAnim('title', 'bounce')) #' } -#' shinyApp(ui, server) +#'if(interactive()) shinyApp(ui, server) #'} #'@seealso \code{\link{withAnim}} #' diff --git a/man/addHoverAnim.Rd b/man/addHoverAnim.Rd index 97b019e..95578f5 100644 --- a/man/addHoverAnim.Rd +++ b/man/addHoverAnim.Rd @@ -23,9 +23,9 @@ ui <- fluidPage( tags$div(id = 'title', h1('HOVER ON ME')) ) server <- function(input, output, session){ - observe(addHoverAnim(session, 'title', 'bounce')) + observe(addHoverAnim('title', 'bounce')) } -shinyApp(ui, server) +if(interactive()) shinyApp(ui, server) } } \seealso{ diff --git a/man/addScrollAnim.Rd b/man/addScrollAnim.Rd index f7ba39f..e317a92 100644 --- a/man/addScrollAnim.Rd +++ b/man/addScrollAnim.Rd @@ -30,9 +30,9 @@ ui <- fluidPage( tags$div(id = 'title', h1('I ANIMATE ON SCROLL')) ) server <- function(input, output, session){ - observe(addScrollAnim(session, 'title', 'bounce')) + observe(addScrollAnim('title', 'bounce')) } -shinyApp(ui, server) +if(interactive()) shinyApp(ui, server) } } \seealso{ diff --git a/man/startAnim.Rd b/man/startAnim.Rd index 720c209..f57af32 100644 --- a/man/startAnim.Rd +++ b/man/startAnim.Rd @@ -25,10 +25,10 @@ ui <- fluidPage( ) server <- function(input, output, session){ observeEvent(input$button,{ - startAnim(session, 'title', 'bounce') + startAnim('title', 'bounce') }) } -shinyApp(ui, server) +if(interactive()) shinyApp(ui, server) } } \seealso{