File: shiny-ggvis.Rd

package info (click to toggle)
r-cran-ggvis 0.4.7%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,716 kB
  • sloc: javascript: 7,373; sh: 25; makefile: 2
file content (87 lines) | stat: -rw-r--r-- 2,353 bytes parent folder | download | duplicates (2)
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/shiny.R, R/shiny_layout.R
\name{shiny-ggvis}
\alias{shiny-ggvis}
\alias{bind_shiny}
\alias{bind_shiny_ui}
\alias{ggvisOutput}
\title{Connect a ggvis graphic to a shiny app.}
\usage{
bind_shiny(
  vis,
  plot_id,
  controls_id = NULL,
  ...,
  session = shiny::getDefaultReactiveDomain()
)

bind_shiny_ui(vis, controls_id, session = shiny::getDefaultReactiveDomain())

ggvisOutput(plot_id = rand_id("plot_id"))
}
\arguments{
\item{vis}{A ggvis object, or a reactive expression that returns a ggvis
object.}

\item{plot_id}{unique identifier to use for the div containing the ggvis plot.}

\item{controls_id}{Unique identifier for controls div.}

\item{...}{Other arguments passed to \code{as.vega}.}

\item{session}{A Shiny session object.}
}
\description{
Embedding ggvis in a shiny app is easy. You need to make a place for it in
your \code{ui.r} with \code{ggvisOutput}, and tell your \code{server.r}
where to draw it with \code{bind_shiny}. It's easiest to learn by example:
there are many shiny apps in \code{demo/apps/} that you can learn from.
}
\section{Client-side}{

In your UI, use \code{ggvisOutput()} in \code{ui.r} to insert an html
placeholder for the plot.

If you're going to be using interactive controls generated by ggvis,
use \code{\link[shiny]{renderUI}()} to add a place holder. By convention,
if the id of plot placehold is called "plot", call the controls placeholder
"plot_ui".
}

\section{Server-side}{

When you run ggvis plot interactively, it is automatically plotted because
it triggers the default print method. In shiny apps, you need to
explicitly render the plot to a specific placeholder with
\code{bind_shiny}:

\code{p \%>\% bind_shiny("plot")}

If the plot has controls, and you've reserved space for them in the UI,
supply the name of the placeholder as the third argument:

\code{p \%>\% bind_shiny("plot", "plot_ui")}
}

\examples{
## Run these examples only in interactive R sessions
if (interactive()) {

# Simplest possible app:
library(shiny)
runApp(list(
  ui = bootstrapPage(
    ggvisOutput("p"),
    uiOutput("p_ui")
  ),
  server = function(..., session) {
    mtcars \%>\%
      ggvis(~wt, ~mpg) \%>\%
      layer_points() \%>\%
      layer_smooths(span = input_slider(0, 1)) \%>\%
      bind_shiny("p", "p_ui")
  }
))

}
}