Learn R Programming

NGLVieweR (version 1.4.0)

updateRock: Update Rock

Description

Start rock animation and stop spinning. Works on an existing NGLVieweR object in Shinymode.

Usage

updateRock(NGLVieweR_proxy, rock = TRUE)

Value

API call containing NGLVieweR

id and list of message parameters.

Arguments

NGLVieweR_proxy

A NGLVieweR object.

rock

If TRUE (default), start rocking and stop spinning.

See Also

  • setRock()

  • NGLVieweR_example() See example "updateAnimation".

Other animations: setRock(), setSpin(), updateSpin(), updateZoomMove()

Examples

Run this code
if (FALSE) {
NGLVieweR_proxy("structure") %>% updateRock(TRUE)
}

if (interactive()) {
library(shiny)

ui = fluidPage(
  titlePanel("Viewer with API inputs"),
  sidebarLayout(
    sidebarPanel(
      radioButtons("animate", label = "Animation",
      choices = c("None", "Spin", "Rock"), selected = "None")
    ),
    mainPanel(
      NGLVieweROutput("structure")
    )
  )
)
server = function(input, output) {
  output$structure <- renderNGLVieweR({
    NGLVieweR("7CID") %>%
      addRepresentation("cartoon",
      param = list(name = "cartoon", color="red"))
  })

  observeEvent(input$animate,{
    if(input$animate == "Rock"){
      NGLVieweR_proxy("structure") %>%
      updateRock(TRUE)
    } else if(input$animate == "Spin") {
      NGLVieweR_proxy("structure") %>%
      updateSpin(TRUE)
    } else{
      NGLVieweR_proxy("structure") %>%
      updateRock(FALSE) %>%
      updateSpin(FALSE)
    }
  })
 }
shinyApp(ui, server)
}

Run the code above in your browser using DataLab