library(htmlwidgets)
library(slickR)
Let’s start easy: show the team logos one at a time
slickR(obj = nba_player_logo$uri,height = 100, width = "95%")
Let’s add dots with the settings
function
slickR(obj = nba_player_logo$uri,height = 100, width = "95%") +
settings(dots = TRUE)
There are many more settings you can define, such as
autoplay
. For all the settings go to slick.js homepage
slickR(obj = nba_player_logo$uri,height = 100, width = "95%") +
settings(dots = TRUE, autoplay = TRUE)
There are players on each team, so lets group the starting five together and have each dot correspond with a team:
<- settings(
opts dots = TRUE,
initialSlide = 0,
slidesToShow = 5,
slidesToScroll = 5,
focusOnSelect = TRUE)
slickR(obj = nba_player_logo$uri,height = 100, width = "95%") +
opts
You can add links to each element in the slide using the
objLinks
parameter. The links are by default set to
target = '_blank'
, so they will open a new window/tab on
click.
<- slickR(obj = nba_player_logo$uri,
slick_link objLinks = nba_player_logo$player_home,
height = 100, width = "95%")
+ opts slick_link
Sometimes the dots won’t be informative enough so we can switch them
with an HTML object, such as text or other images. We can pass to the
customPaging
argument javascript code using the
htmlwidgets::JS
function.
<- htmlwidgets::JS("function(slick,index) {
cP1 return '<a>'+(index+1)+'</a>';
}")
<- settings(
opts_dot_number initialSlide = 0,
slidesToShow = 5,
slidesToScroll = 5,
focusOnSelect = TRUE,
dots = TRUE,
customPaging = cP1
)
<- slickR(
slick_dots obj = nba_player_logo$uri,
height = 100,
width = "95%"
)
+ opts_dot_number slick_dots
<- JS("function(slick,index) {
cP2 return '<a><img src= ' + dotObj[index] + ' width=100% height=100%></a>';
}")
<-
opts_dot_logo settings(
initialSlide = 0,
slidesToShow = 5,
slidesToScroll = 5,
focusOnSelect = TRUE,
dots = TRUE,
customPaging = cP2
)
# Putting it all together in one slickR call
<- htmltools::tags$script(
s2 sprintf("var dotObj = %s", jsonlite::toJSON(nba_team_logo$uri))
)
<- slickR(
slick_dots_logo obj = nba_player_logo$uri,
height = 100,
width = "95%"
+ opts_dot_logo
)
::browsable(htmltools::tagList(s2, slick_dots_logo)) htmltools
You can stack carousels one on top of the other with the
%stack%
operator
<- slickR(obj = nba_player_logo$uri, height = 100, width = "95%")
slick_up_stack
<- slickR(obj = nba_player_logo$uri, height = 100, width = "95%")
slick_down_stack
%stack% slick_down_stack slick_up_stack
There are instances when you have many outputs at once and do not
want to go through all, so you can stack and synch two carousels one for
viewing and one for searching with the %synch%
operator.
<- slickR(obj = nba_player_logo$uri, height = 100, width = "95%")
slick_up_synch
<- slickR(obj = nba_player_logo$uri, height = 100, width = "95%")
slick_down_synch
%synch% slick_down_synch slick_up_synch