graph3d-shiny: Shiny bindings for graph3d

Description Usage Arguments Examples

Description

Output and render functions for using graph3d within Shiny applications and interactive Rmd documents.

Usage

1
2
3
graph3dOutput(outputId, width = "100%", height = "400px")

renderGraph3d(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from

width, height

dimensions, must be valid CSS units (like '100%', '400px', 'auto') or a number, which will be coerced to a string and have 'px' appended

expr

an expression that generates a graph3d HTML widget

env

the environment in which to evaluate expr

quoted

logical, whether expr is a quoted expression (with quote()); this is useful if you want to save an expression in a variable

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
if(interactive()) {

# 'surfaceColors' example ####

library(shiny)
library(viridisLite)
library(graph3d)

x <- y <- seq(-10, 10, length.out = 100)
dat <- expand.grid(x = x, y = y)
f <- function(x, y){
  r <- sqrt(x^2+y^2)
  10 * ifelse(r == 0, 1, sin(r)/r)
}
dat <- transform(dat, z = f(x, y))

ui <- fluidPage(
  br(),
  fluidRow(
    column(
      width = 2,
      radioButtons("colors", "Colors",
                   c("viridis", "inferno", "magma", "plasma", "cividis"))
    ),
    column(
      width = 10,
      graph3dOutput("mygraph", height = "550px")
    )
  )
)

server <- function(input, output, session){

  Colors <- reactive({
    colors <- switch(
      input$colors,
      viridis = viridis(5),
      inferno = inferno(5),
      magma = magma(5),
      plasma = plasma(5),
      cividis = cividis(5)
    )
    substring(colors, 1L, 7L)
  })

  output[["mygraph"]] <- renderGraph3d({
    graph3d(dat, surfaceColors = Colors(), showLegend = FALSE)
  })

}

shinyApp(ui, server)

}

if(interactive()) {

# 'onclick' example ####

library(shiny)
library(graph3d)

dat <- data.frame(x = rnorm(30), y = rnorm(30), z = rnorm(30))

onclick <- c(
  "function(point){",
  "  Shiny.setInputValue('point', point);",
  "}"
)

ui <- fluidPage(
  br(),
  fluidRow(
    column(
      width = 4,
      h4("You clicked:"),
      verbatimTextOutput("pointClicked")
    ),
    column(
      width = 8,
      graph3dOutput("mygraph", height = "550px")
    )
  )
)

server <- function(input, output, session){

  output[["mygraph"]] <- renderGraph3d({
    graph3d(dat, type = "dot", width = "550px", height = "550px",
            onclick = JS(onclick), tooltip = FALSE)
  })

  output[["pointClicked"]] <- renderPrint({
    input[["point"]]
  })

}

shinyApp(ui, server)

}

graph3d documentation built on Nov. 13, 2020, 5:09 p.m.