library(shiny)
library(tidyverse)
library(leaflet)
library(DT)
library(threejs)
library(RColorBrewer)

ui <- page_navbar(
  title = "Test",
  theme = bs_theme(preset = "darkly"),
  nav_panel(
    "Test",
    h2("Leaflet Demonstration"),
    leafletOutput(outputId = "map")
  ),
  nav_panel(
    "Data Table",
    DTOutput(outputId = "table")
  ),
  nav_panel(
    "3D Graphics",
    scatterplotThreeOutput(outputId = "graphics")
  )
)

server <- function(input, output) {
  
  output$map <- renderLeaflet({
    leaflet() |>
      addTiles() |>
      addMarkers(lng = runif(5,-180,180), lat = runif(5,-90,90), popup = "Some random location!")
  })
  
  output$table <- renderDataTable({
    datatable(iris, options = list(pageLength = 10))
  })
  
  output$graphics <- renderScatterplotThree({
    z <- runif(12, 0, 100)
    x <- runif(12, 0, 100)
    y <- runif(12, 0, 100)
    scatterplot3js(x, y, z, color = brewer.pal(12, "Set3"))
  })
}

shinyApp(ui = ui, server = server)
