plotlycrosstalk

In package `crosstalk`, are there have function `bsrows()` and `rows+cols` mixed?


In package crosstalk, there is function bscols() make plots align in a row. But I cant't find function bsrows() and rows+cols mixed , is any package have such function? Thanks!

library(plotly)
library(tidyr)
library(crosstalk)

m <- gather(mtcars, variable, value, -vs)
msd <- highlight_key(m, ~variable)
gg <- ggplot(msd, aes(factor(vs), value)) + 
  geom_jitter(alpha = 0.3)

bscols(
  widths = c(11, 6, 6),
  filter_select("id", "Select a variable", msd, ~variable, multiple = FALSE),
  ggplotly(gg, dynamicTicks = "y") %>% layout(margin = list(l = 30)),
  plot_ly(msd, x = ~jitter(vs), y = ~value) %>% add_markers(alpha = 0.3)
)

Solution

  • I was searching for the same thing until realizing that 12 is the maximum number of columns in crosstalk::bscols(). This means that you can put every widget on next row just by specifying widths = 12 for the previous one. By adjusting widths you can adjust both columns and when new rows are introduces. It is probably not the interface you were hoping for but it works. Here is an example with your widgests on separate rows (I added htmltools to use breaks):

    library(plotly)
    library(tidyr)
    library(crosstalk)
    library(htmltools)
    
    m <- gather(mtcars, variable, value, -vs)
    msd <- highlight_key(m, ~variable)
    gg <- ggplot(msd, aes(factor(vs), value)) + 
      geom_jitter(alpha = 0.3)
    
    suppressWarnings({
      bscols(
        widths = c(12, 12, 12),
        filter_select("id", "Select a variable", msd, ~variable, multiple = FALSE),
        htmltools::br(),
        ggplotly(gg, dynamicTicks = "y") %>% layout(margin = list(l = 30)),
        htmltools::br(),
        plot_ly(msd, x = ~jitter(vs), y = ~value) %>% add_markers(alpha = 0.3)
      )
    })