Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion linked-views-shiny.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ The `renderPlotly()` function renders anything that the `plotly_build()` functio

```{r eval = FALSE, summary = "Click to show/hide the code"}
library(shiny)
library(plotly)

cities <- unique(txhousing$city)

Expand Down Expand Up @@ -177,6 +178,7 @@ A little known fact about **plotly** is that you can directly manipulate annotat

```{r eval = FALSE, summary = "Click to show/hide the code"}
library(shiny)
library(plotly)

ui <- fluidPage(
plotlyOutput("p"),
Expand Down Expand Up @@ -229,6 +231,7 @@ Figure \@ref(fig:shiny-drag-circle) demonstrates directly manipulating a circle

```{r eval = FALSE, summary = "Click to show/hide the code"}
library(shiny)
library(plotly)

ui <- fluidPage(
plotlyOutput("p"),
Expand Down Expand Up @@ -302,6 +305,7 @@ Remember every **graph** has two critical components: data (i.e., traces) and la

```{r eval = FALSE, summary = "Click to show/hide the code"}
library(shiny)
library(plotly)

ui <- fluidPage(
plotlyOutput("parcoords"),
Expand Down Expand Up @@ -364,6 +368,7 @@ Figure \@ref(fig:shiny-corrplot) allows one to click on a cell of correlation he

```{r eval = FALSE, summary = "Click to show/hide the code"}
library(shiny)
library(plotly)

# cache computation of the correlation matrix
correlation <- round(cor(mtcars), 3)
Expand Down Expand Up @@ -422,6 +427,7 @@ By default, `event_data()` only invalidates a reactive expression when the value

```{r eval = FALSE, summary = "Click to show/hide the code"}
library(shiny)
library(plotly)

ui <- fluidPage(
plotlyOutput("p"),
Expand Down Expand Up @@ -741,6 +747,7 @@ library(shiny)
library(dplyr)
library(readr)
library(purrr) # just for `%||%`
library(plotly)

sales <- read_csv("https://plotly-r.com/data-raw/sales.csv")
categories <- unique(sales$category)
Expand Down Expand Up @@ -804,6 +811,7 @@ A basic drill-down like Figure \@ref(fig:shiny-drill-down-pie) is somewhat usefu
```{r eval = FALSE, summary = "Click to show/hide the code"}
library(shiny)
library(dplyr)
library(plotly)
library(readr)

sales <- read_csv("https://plotly-r.com/data-raw/sales.csv")
Expand Down Expand Up @@ -1162,6 +1170,7 @@ Figure \@ref(fig:shiny-crossfilter-naive) demonstrates the simplest way to imple
library(shiny)
library(dplyr)
library(nycflights13)
library(plotly)

ui <- fluidPage(
plotlyOutput("arr_time"),
Expand Down Expand Up @@ -1216,6 +1225,7 @@ library(shiny)
library(dplyr)
library(nycflights13)
library(ggstat)
library(plotly)

arr_time <- flights$arr_time
dep_time <- flights$dep_time
Expand Down Expand Up @@ -1343,4 +1353,4 @@ Sometimes **shiny** gets a bad rap for being too slow or unresponsive, but as we

Maybe your IT administrator simply won't allow you to distribute your work outside of a standalone HTML file. Figure \@ref(fig:shiny-corrplot) is just one example of a linked graphic that *could* be replicated using the graphical querying framework from Section \@ref(graphical-queries), but it would require pre-computing every possible view (which becomes un-manageable when there are many possible selections) and posing the update logic as a database query. When users are only allowed to select (e.g., click/hover) a single element at a time, the number of possible selections increases linearly with the number of elements, but when users are allowed to select any subset of elements (e.g., scatterplot brushing), the number of possible selections explodes (increases at a factorial rate). For example, adding a cell to Figure \@ref(fig:shiny-corrplot) only adds one possible selection, but if we added more states to Figure \@ref(fig:shiny-corrplot), the number of possible states goes from 50! to 51!.

Even in the case that you need a standalone HTML file and the R API that **plotly** provides doesn't support the type of interactivity that you desire, you can always layer on additional JavaScript to hopefully achieve the functionality you desire. This can be useful for something as simple as opening a hyperlink when clicking on marker of a plotly graph. This topic is covered in Chapter \@ref(javascript).
Even in the case that you need a standalone HTML file and the R API that **plotly** provides doesn't support the type of interactivity that you desire, you can always layer on additional JavaScript to hopefully achieve the functionality you desire. This can be useful for something as simple as opening a hyperlink when clicking on marker of a plotly graph. This topic is covered in Chapter \@ref(javascript).