Plotly not working in Jupyter R kernel

Plotly doesn’t seem to be working in my Jupyter R kernel notebooks correctly. For example, the following exact code from a Plotly example throws the error listed below:

library(plotly) set.seed(100) d <- diamonds[sample(nrow(diamonds), 1000), ] plot_ly(d, x = carat, y = price, text = paste("Clarity: ", clarity), mode = "markers", color = carat, size = carat)

"Error in plot_ly(d, x = carat, y = price, text = paste("Clarity: ", clarity), : object 'carat' not found
Traceback:

1. plot_ly(d, x = carat, y = price, text = paste("Clarity: ", clarity), 
 .     mode = "markers", color = carat, size = carat)"

Unfortunately the error message “object not found” is not super informative. Any suggestions or ideas why Plotly isn’t working as predicted on well-known dataframes in Jupyter R notebooks?