Making the Connection with Crosstalk

[This article was first published on The Data Sandbox, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I recently wrote a post about creating dashboards in R which was based on the Flexdashboard library. My largest criticism was the lack of communication between visualizations on the same dashboard. This was before I learned about the Crosstalk package which adds this feature to html widgets, such as the Flexdashboard, to at least a limited degree.

Initialization

The Crosstalk package is available on CRAN and is loaded along with other important packages for this demonstration.

install.packages("crosstalk")
library(crosstalk)
library(tidyverse)
library(flexdashboard)
library(plotly)

I have decided to use a Toronto Open dataset about city audits for apartment buildings. I limited the features to only the ones that I feel will be interesting to look at. More information about the data set can be found here.

download.file("https://ckan0.cf.opendata.inter.prod-toronto.ca/dataset/4ef82789-e038-44ef-a478-a8f3590c3eb1/resource/979fb513-5186-41e9-bb23-7b5cc6b89915/download/Apartment%20Building%20Evaluation.csv", "data.csv")
df <- read_csv("data.csv") %>%
        select(lng = LONGITUDE, 
               lat = LATITUDE, 
               SCORE, 
               YEAR_BUILT, 
               SITE_ADDRESS, 
               PROPERTY_TYPE) %>% 
        slice_sample(n = 200)

The key to the crosstalk library is the SharedData functions. An object is created when a Data Frame is passed to the SharedData$new function. This is what enables communication between plots.

shared_df <- SharedData$new(df)

Dashboard Creation

The dashboard is created pretty much as previous mentioned in my dashboard post, with the exception that the shared Data Frame object is passed rather than the Data Frame.

The dashboard can include filters that are very similar to the Shiny Apt filters, with the filter_* family of functions.

filter_slider("Score", "SCORE", shared_df, ~SCORE, round = TRUE)
filter_checkbox("Property Type", "PROPERTY_TYPE", shared_df, ~PROPERTY_TYPE, inline = TRUE)

Conclusion

The Crosstalk package does add some significant connectivity to Flex Dashboards. It is relatively simple to use with some basic functions. It does have the issue of not working with aggregating data. The utility of finding the mean value of a selection is something Tableu and PowerBI are still superior at. I think that it is still a welcome improvement.

Final Dashboard

Photo by Jason Goodmanon Unsplash

To leave a comment for the author, please follow the link and comment on their blog: The Data Sandbox.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)