bwlewis / rthreejs

Three.js widgets for R and shiny
http://bwlewis.github.io/rthreejs
Other
303 stars 64 forks source link

Support Shiny (Bootstrap) tabs #75

Closed vkapartzianis closed 6 years ago

vkapartzianis commented 6 years ago

Handle Bootstrap tabs, the same way slides are handled (by subscribing to "shown" events). Use the following as a test:

library("shiny")
library("threejs")

plot.statistics <- function(n)
{
  x_data <- runif(1000)
  y_data <- runif(1000)
  z_data <- x_data^n + y_data^n

  ui <- fluidPage(
    title = "x-y-z",
    fluidRow(column(width = 12, scatterplot3js(x = x_data,
                                               y = y_data,
                                               z = z_data,
                                               color = rainbow(length(z_data)),
                                               pch = ".",
                                               size = 0.2,
                                               labels = paste(z_data, " @ ", x_data, "_", y_data, sep = ""),
                                               axisLabels = c("x", "z", "y"),
                                               cex.lab = 0.2,
                                               cex.axis = 0.2,
                                               main = "x-y-z"))))

  return(list("tab.title" = paste("Surface ", n, sep = ""),
              "tab.content" = ui))
}

tabs <- mapply(plot.statistics,
               n = c(1, 2, 3),
               SIMPLIFY = FALSE,
               USE.NAMES = FALSE)

tabPanels <- lapply(seq_len(length(tabs)), function(i) tabPanel(tabs[[i]]$tab.title, tabs[[i]]$tab.content))

ui <- fluidPage(title = "3d dynamic plots", mainPanel(do.call(tabsetPanel, tabPanels)))

browseURL(htmltools:::html_print(ui))
bwlewis commented 6 years ago

Thanks! Sorry it took a while to merge this, I get behind sometimes...