Get startedGet started for free

Adding checkboxes

Adding checkbox filters allows you to quickly "call out" a group, or set of groups, which is particularly useful when exploring how associations change between groups.

In this exercise, your task is to add a checkbox filter for the region to a scatterplot of the housing price index against homeownership in 2017.

plotly and crosstalk have already been loaded for you, and the data are stored in us2017.

This exercise is part of the course

Intermediate Interactive Data Visualization with plotly in R

View Course

Exercise instructions

  • Add a checkbox filter for region to the left of the scatterplot stored in p17.
  • Restrict the width of the checkboxes to 3 columns, and allow the plot to span the remainder of the columns.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# shared data object
shared_us <- SharedData$new(us2017, key = ~region)

# scatterplot of housing price index against homeownership
p17 <- shared_us %>%
  plot_ly(x = ~home_owners, y = ~house_price, color = ~region, height = 400) %>%
  add_markers()
  
# add a column of checkboxes for region to the left of the plot
___(___,
  ___(id = "region", label = "Region", sharedData = ___, group = ___),
  p17
)
Edit and Run Code