View plotly-shiny-examples.R
library(shiny)
library(plotly)
# I keep a collection of my (plotly and non-plotly) apps here
# https://github.com/cpsievert/apps
runGitHub("apps", "cpsievert", subdir = "shiny/apps/plotlyAg")
browseURL("https://github.com/cpsievert/apps/blob/master/shiny/apps/plotlyAg/app.R")
# The plotly package ships with some rmarkdown/shiny examples
browseURL("https://github.com/ropensci/plotly/tree/master/inst/examples")
View ggbasic.json
{"x":{"data":[{"orientation":"v","width":[0.310344827586207,0.310344827586207,0.310344827586207,0.310344827586207,0.310344827586206,0.310344827586207,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586207,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206,0.310344827586206],"base":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"x":[0.931034482758621,1.24137931034483,1.55172413793103,1.86206896551724,2.17241379310345,2.48275862068966,2.79310344827586,3.10344827586207,3.41379310344828,3.72413793103448,4.03448275862069,4.3448275862069,4.6551724137931,4.96551724137931,5.27586206896552,5.58620689655172,5.89655172413793,6.20689655172414,6.51724137931035,6.82758620689655,7.13793103448276,7.448275862
View sankey.R
library(plotly)
plot_ly(
type = 'sankey',
node = list(
label = c("a","b", "c", "d", "e", "f", "g", "h"),
color = c("black","black","black","black","black","black",
"black","black"),
pad = 15,
thickness = 15,
View arrow.R
library(grid)
(a <- arrow())
#> $angle
#> [1] 30
#>
#> $length
#> [1] 0.25inches
#>
#> $ends
#> [1] 2
View restyle.R
library(plotly)
library(htmlwidgets)
plot_ly(x = c(1, 2), y = c(1, 2)) %>%
onRender(
'function(el, x) {
setTimeout(function() {
var gd = document.getElementById(el.id);
var obj = {"mode": "markers"};
for (var i = 0; i < 10; i++) {
View click-to-show-text.R
library(sf)
library(dplyr)
library(albersusa)
library(crosstalk)
library(plotly)
usa <- usa_sf("laea")
# st_centroid gets the center POINT of polygons
uscenter <- usa %>%
View europe.R
library(tidyverse)
library(plotly)
# I'm being lazy, please don't do this
# setwd("~/Downloads/Version 2_0_1/")
d <- read_csv('GEOSTAT_grid_POP_1K_2011_V2_0_1.csv') %>%
rbind(read_csv('JRC-GHSL_AIT-grid-POP_1K_2011.csv') %>%
mutate(TOT_P_CON_DT = '')) %>%
mutate(
View set-values.R
library(crosstalk)
library(htmltools)
m <- SharedData$new(mtcars)
set_values <- function(w, sharedData, values) {
script <- sprintf(
"HTMLWidgets.addPostRenderHandler(function() { return crosstalk.group('%s').var('%s').set(%s); })",
sharedData$groupName(), "filter", jsonlite::toJSON(values)
)
View dynamic-y.R
library(plotly)
library(tidyr)
library(crosstalk)
m <- gather(mtcars, variable, value, -vs)
msd <- SharedData$new(m, ~variable)
gg <- ggplot(msd, aes(factor(vs), value)) +
geom_jitter(alpha = 0.3)
bscols(widths = c(11, 6, 6),
View ggplotly-sf.R
# devtools::install_github("ropensci/plotly")
library(plotly)
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"))
# shared data will make the polygons "query-able"
ncsd <- crosstalk::SharedData$new(nc)
p <- ggplot(ncsd) +
geom_sf(aes(fill = AREA, text = paste0(NAME, "\n", "FIPS: ", FIPS))) +