diff --git a/linked-views-shiny.Rmd b/linked-views-shiny.Rmd index 5cf6c39..0d8749b 100644 --- a/linked-views-shiny.Rmd +++ b/linked-views-shiny.Rmd @@ -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) @@ -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"), @@ -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"), @@ -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"), @@ -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) @@ -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"), @@ -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) @@ -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") @@ -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"), @@ -1216,6 +1225,7 @@ library(shiny) library(dplyr) library(nycflights13) library(ggstat) +library(plotly) arr_time <- flights$arr_time dep_time <- flights$dep_time @@ -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). \ No newline at end of file +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).