Toggle yaxis to log/linear in subplots with a button in R


I want to have two subplots with shared x axis, and I want to be able to toggle a log/linear yaxis for both of them at the same time. I was able to make it work on single plots, and I’m able to build the subplots with x axis shared. However, when I try to modify the subplot layout, I end up with a weird behavior. Any clue on how to do it in R?

Here is what I manage to do today:


p1 <- plot_ly(economics, x = ~date, y = ~uempmed)
p2 <- plot_ly(economics, x = ~date, y = ~unemploy)
subplot(p1, p2, nrows = 2, shareX = TRUE) %>% 
  layout(updatemenus = list(
      type = "dropdown",
      direction = "right",
      y = 0.8,
      buttons = list(
        list(method = "relayout",
             args = list("yaxis", list(type = "log")),
             label = "log"),
        list(method = "relayout",
             args = list("yaxis", list(type = "linear")),
             label = "linear")