Black Lives Matter. Please consider donating to Black Girls Code today.

Date Formats Not Working in Hovertemplate Using Plot_ly()

I’m trying to add a date format to the tooltip using hovertemple. However, it seems like date formats are not working for me. Can anyone help me understand what I’m doing wrong? The tooltip just displays the text “Date: %{x|%B %Y}” rather than the formatted date. If I remove the date format, then the date does display as expected.

##Here is some code using a modified example from https://plot.ly/r/tick-formatting/

df <- read.csv(‘https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv’)

p <- plot_ly(
type = “scatter”,
x = df$Date,
y = df$AAPL.High,
name = ‘AAPL High’,
mode = “lines”,
line = list(
color = ‘#17BECF
),
hovertemplate = paste(
‘Date: %{x|%B %Y}’)
) %>%
layout(
title = “Time Series with Custom Date-Time Format”,
xaxis = list(
type = ‘date’,
tickformat = “%d %B (%a) %Y”
))
p