No error here:
library(tidyverse)
library(plotly)
df <- tibble(X1 = c(100, 200, 300),
X2 = c('2010', '2011', '2012'))
df2 <- tibble(X1 = c(200, 300, 100),
X2 = c('2010', '2011', '2012'))
plot_ly() %>%
add_trace(x = df$X1, y = df$X2, type = "bar", name = "test") %>%
add_trace(x = df2$X1, y = df2$X2, type = "bar", name = "test2") %>%
layout(
legend = list(x = 0, y = 1.5),
title = "Yearly Data"
)