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 <swechhyabista@gmail.com> 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..3d0d798 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 @@ -37,14 +36,15 @@ 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}} #' -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 @@ -64,13 +63,14 @@ startAnim <- function(session, 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}} #' -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 @@ -97,13 +96,14 @@ addHoverAnim <- function(session, 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}} #' -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..95578f5 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/}} @@ -25,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 fa97473..e317a92 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/}} @@ -32,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 7bdb8b1..f57af32 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/}} @@ -27,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{