Hi I've been adding onto an R Shiny project of mine and I've had a hard time finding information on working with ggplotly tooltips. I have a graph that plots NBA PPG vs shooting efficiency for the top scorers, and I have a basic tooltip set up displaying some information about the player when the user hovers over them.
The data comes with a variable called urlPlayerHeadshot, which gives links to a png picture of the player (for example, here is Anthony Davis' - https://ak-static.cms.nba.com/wp-content/uploads/headshots/nba/latest/260x190/203076.png). Every Player in the graph has their own link & image.
Below is the graph and the code I use to produce it. I've also included an example of what my data frame looks like.
top20_plot <- function(df){
p <- df %>%
ggplot(aes(avg_PTS, season_ts_percent, fill = Top5)) +
geom_point(size = 6, alpha = 0.7, pch = 21, color = 'black', aes(text = paste0(Player, '<br>',
Team, ' (', Wins, '-', Losses, ')', '<br>',
'PPG: ', round(avg_PTS, 1), '<br>',
'TS%: ', round(season_ts_percent * 100, 1), '%', '<br>',
'Games Played: ', GP))) +
scale_y_continuous(labels = scales::percent, limits=c(.48, .72), breaks=seq(.48, .72, by = .08)) +
scale_fill_manual(values = c('light blue', 'orange')) +
labs(color = 'Top 5 MVP Candidate', fill = 'Top 5 MVP Candidate',
title = 'Player Efficiency Tracker
PPG vs TS% for all 20+ PPG Scorers',
x = 'Average Points per Game',
y = 'True Shooting Percentage') +
theme_jacob() +
theme(plot.title = element_text(hjust = 0.5), legend.position = 'top')
ggplotly(p, tooltip = c('text')) %>%
layout(legend = list(orientation = "h", x = 0.35))
}
top20_plot(top_20pt_scorers)
I was wondering if there is a solution to somehow point to this variable and include that png in the tooltip of the graph, or if this is simply not possible using ggplotly. Thanks!