Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
)
like image 943
anderwyang Avatar asked Oct 23 '25 23:10

anderwyang


1 Answers

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)
  )
})
like image 146
Claudiu Papasteri Avatar answered Oct 26 '25 14:10

Claudiu Papasteri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!