Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Dropdowns and multiple legends

Hello, I have a summarized dataset with counts by a number of grouping variables, in this case three (but there could be more). I would like to make this plot interactive, ideally with the help of 2-3 dropdown menus (Product, Product2, Region; data and code below).

  1. Does anyone have some sample code for dropdowns that they could share? I took a look at the sin/cos and scatter/histogram examples, but can’t figure out how to adapt that framework to my case, where the only requirement is that certain time series would be selected for plotting.
  2. Multiple legends (as in the ggplot) could also be acceptable. Except that plotly automatically collapses the 2 legends into 1. This simply does not work, because for example a legend with 6 levels (color) and another with 4 levels (shape) would explode into a “thing” with up to 24 levels, which nobody could use.
  3. The dates are misformatted in the browser. The tooltips say Date=17288, when in fact Date=2017-05-02. Sure that’s the underlying numeric representation; but since class(mydf$Date) = “Date”, this could have been automatically displayed in a user-readable format. Assuming this issue is not going to be fixed in plotly, is there a way of applying human-readable formats to various fields, such as currency, comma, percent, date?

Thank you in advance.

mydf <-
structure(list(Date = structure(c(17274, 17274, 17274, 17274,
17274, 17274, 17274, 17274, 17274, 17274, 17274, 17274, 17274,
17274, 17274, 17274, 17274, 17274, 17274, 17274, 17274, 17281,
17281, 17281, 17281, 17281, 17281, 17281, 17281, 17281, 17281,
17281, 17281, 17281, 17281, 17281, 17281, 17281, 17281, 17281,
17281, 17281, 17288, 17288, 17288, 17288, 17288, 17288, 17288,
17288, 17288, 17288, 17288, 17288, 17288, 17288, 17288, 17288,
17288, 17288, 17288, 17288, 17288), class = “Date”), Product = c(“Pr 2”,
“Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”,
“Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”,
“Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”,
“Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”,
“Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”,
“Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”,
“Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”,
“Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”, “Pr 2”), Product2 = c(“Prod 1”,
“Prod 1”, “Prod 1”, “Prod 1”, “Prod 1”, “Prod 2”, “Prod 6”, “Prod 6”,
“Prod 6”, “Prod 6”, “Prod 6”, “Prod 6”, “Prod 9”, “Prod 9”, “Prod 9”,
“Prod 9”, “Prod 9”, “Prod 10”, “Prod 10”, “Prod 10”, “Prod 10”,
“Prod 1”, “Prod 1”, “Prod 1”, “Prod 1”, “Prod 1”, “Prod 2”, “Prod 6”,
“Prod 6”, “Prod 6”, “Prod 6”, “Prod 6”, “Prod 6”, “Prod 9”, “Prod 9”,
“Prod 9”, “Prod 9”, “Prod 9”, “Prod 10”, “Prod 10”, “Prod 10”,
“Prod 10”, “Prod 1”, “Prod 1”, “Prod 1”, “Prod 1”, “Prod 1”,
“Prod 2”, “Prod 6”, “Prod 6”, “Prod 6”, “Prod 6”, “Prod 6”, “Prod 6”,
“Prod 9”, “Prod 9”, “Prod 9”, “Prod 9”, “Prod 9”, “Prod 10”,
“Prod 10”, “Prod 10”, “Prod 10”), Region = c(“Reg 2”, “Reg 3”,
“Reg 4”, “Reg 5”, “Reg 8”, “Reg 8”, “Reg 1”, “Reg 2”, “Reg 3”,
“Reg 4”, “Reg 5”, “Reg 6”, “Reg 1”, “Reg 2”, “Reg 3”, “Reg 4”,
“Reg 5”, “Reg 2”, “Reg 4”, “Reg 6”, “Reg 8”, “Reg 2”, “Reg 3”,
“Reg 4”, “Reg 5”, “Reg 8”, “Reg 8”, “Reg 1”, “Reg 2”, “Reg 3”,
“Reg 4”, “Reg 5”, “Reg 6”, “Reg 1”, “Reg 2”, “Reg 3”, “Reg 4”,
“Reg 5”, “Reg 2”, “Reg 4”, “Reg 6”, “Reg 8”, “Reg 2”, “Reg 3”,
“Reg 4”, “Reg 5”, “Reg 8”, “Reg 8”, “Reg 1”, “Reg 2”, “Reg 3”,
“Reg 4”, “Reg 5”, “Reg 6”, “Reg 1”, “Reg 2”, “Reg 3”, “Reg 4”,
“Reg 5”, “Reg 2”, “Reg 4”, “Reg 6”, “Reg 8”), Quantity = c(0,
3, 3, 1, 206, 20, 133, 84, 9, 116, 63, 1, 3, 32, 21, 173, 14,
0, 59, 680, 1, 0, 3, 3, 1, 207, 23, 133, 85, 9, 118, 63, 1, 3,
32, 21, 172, 14, 0, 74, 673, 1, 0, 3, 3, 1, 207, 26, 130, 90,
10, 81, 64, 1, 3, 32, 21, 173, 14, 0, 82, 668, 1)), .Names = c(“Date”,
“Product”, “Product2”, “Region”, “Quantity”), row.names = c(NA,
-63L), class = “data.frame”)

require(ggplot2)
require(plotly)
p <- ggplot(mydf, aes(Date, Quantity, color=Region, shape=Product)) + geom_line() + geom_point() +
facet_wrap(~ Product2) +
labs(title=‘ggplot solution that works reasonably well’)
print§
ggplotly§