Dynamic valueBox Module

I am trying to create a value box module that uses a custom valuebox design as a function and want the parameters to be dynamics. The code is throwing an error that I can figure out. here is my codes

# Custom valueBox function
valueBoxSpark <- function(value, title, sparkobj = NULL, subtitle, info = NULL, 
                          icon = NULL, color = "aqua", width = 4, href = NULL){
  
  shinydashboard:::validateColor(color)
  
  if (!is.null(icon))
    shinydashboard:::tagAssert(icon, type = "i")
  
  info_icon <- tags$small(
    tags$i(
      class = "fa fa-info-circle fa-lg",
      title = info,
      `data-toggle` = "tooltip",
      style = "color: rgba(255, 255, 255, 0.75);"
    ),
    # bs3 pull-right 
    # bs4 float-right
    class = "pull-right float-right"
  )
  
  boxContent <- div(
    class = paste0("small-box bg-", color),
    div(
      class = "inner",
      tags$small(title),
      if (!is.null(sparkobj)) info_icon,
      h3(value),
      if (!is.null(sparkobj)) sparkobj,
      p(subtitle)
    ),
    # bs3 icon-large
    # bs4 icon
    if (!is.null(icon)) div(class = "icon-large icon", icon, style = "z-index; 0")
  )
  
  if (!is.null(href)) 
    boxContent <- a(href = href, boxContent)
  
  div(
    class = if (!is.null(width)) paste0("col-sm-", width), 
    boxContent
  )
}

##############################
# mod_valuebox.R
#
# 
# 
##############################

mod_valuebox_ui <- function(id){
  ns <- NS(id)
  tagList(
    valueBoxOutput(ns("vb"), width=4)
  )
}

#' valuebox Server Functions
#'
#' 
mod_valuebox_server <- function(id,value,title,info,icon,colour){
  moduleServer(id, function(input, output, session){
    ns <- session$ns
    output$vb <- renderValueBox({
      valueBoxSpark(value = value,
                    title = title,
                    info = info,
                    icon =icon,
                    color = colour,
                    width = 4)
    })
  })
}

### UI and server call

server.R
mod_valuebox_server("valuebox_ui_tot",
                 value = 0,
                 title = "Sold",
                 info = "Graphe",
                 icon = icon("water"),
                 colour = "aqua",
)

ui.R
bs4TabItem(
  tabName = "tab1",
  mod_valuebox_ui("valuebox_ui_tot")
)

there is a spurious comma after "aqua" this is a first problem.
secondly, subtitle is a required param for the function you wrote, but you aren't passing it in.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.