RinteRface / argonDash

argon dashboard template
https://rinterface.github.io/argonDash/
138 stars 37 forks source link

Possibility to capture argonDropNavItem in server as an input? #28

Open sarthi2395 opened 4 years ago

sarthi2395 commented 4 years ago

Currently, the dropdown options in argonDropNavItem carry only weblinks, which when clicked redirects to corresponding webpage. Is is possible to update this as a button instead and capture the selection in server?

DivadNojnarg commented 4 years ago

Yup that could be. This is what I am currently doing on all other RinteRface package to allow for more interactivity

sarthi2395 commented 4 years ago

Do you have a gist available as an example?

DivadNojnarg commented 4 years ago

Something really quick and dirty before I push a fix:

library(shiny)
library(argon)
library(argonR)

argonDropdownItem <- function (inputId = NULL, name = NULL, description = NULL, src = NULL, icon = NULL, 
                               status = NULL) {

  itemCl <- "media d-flex align-items-center"

  # add class action-button to rely on the existing shiny input binding
  if (!is.null(inputId)) {
    itemCl <- paste0(itemCl, " btn action-button")
  }

  tags$a(
    id = if (!is.null(inputId)) inputId, 
    class = itemCl, 
    href = src, 
    if (!is.null(icon)) {
      argonIconWrapper(
        iconTag = icon, gradient_color = status, 
        circle = TRUE, size = NULL, status = status, 
        shadow = FALSE, hover_shadow = FALSE)
    },
    tags$div(
      class = "media-body ml-3",
      tags$h6(class = paste0("heading text-", status, " mb-md-1"), name), 
      tags$p(class = "description d-none d-md-inline-block mb-0", description)
    )
  )
}

shinyApp(
  ui = argonDashPage(
    navbar = argonDashNavbar(
      argonDropNav(
        title = "Menu",
        argonDropdownItem(inputId = "test", name = "Hello")
      )
    ),
    sidebar = argonDashSidebar(
      id = "sidebar",
      side = "left",
      size = "md",
      skin = "light"
    ),
    body = argonDashBody("Hello World")
  ),
  server = function(input, output) {
    observeEvent(input$test, {
      showNotification("plop")
    })
  }
)