Passing a list of arguments into a function in R Shiny

Use do.call

do.call("dropdown", c(box_params, 
                      label = "Plot Options Box 1",
                      numericInput(inputId = "box1", 
      label = "Value", min = 1, max = 5, value = 3)))

full code:

library(shiny)
library(shinydashboard)
library(shinyWidgets)
box_params <- list(icon = icon("cogs"), 
                   width = "400px")



ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    box(title = "Box 1",
        dropdownMenu = do.call("dropdown", c(box_params, list(label = "Plot Options Box 1",
                                                              numericInput(inputId = "box1", label = "Value", min = 1, max = 5, value = 3))))
    ),
    box(title = "Box 2",
        dropdownMenu = do.call("dropdown", c(box_params, list(label = "Plot Options Box 2",
                                                              numericInput(inputId = "box2", label = "Value", min = 1, max = 5, value = 3))))
    )
  )
)

server <- function(input, output) { }

shinyApp(ui, server)

output:

enter image description here


I will delete this: but If i do:

library(shiny)
library(shinydashboard)
library(shinyWidgets)

box_params <- list(icon = icon("cogs"), 
                   width = "400px")

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    box(title = "Box 1",
        dropdownMenu = dropdown(box_params,
                                label = "Plot Options Box 1",
                                numericInput(inputId = "box1", label = "Value", min = 1, max = 5, value = 3)
        )
    ),
    box(title = "Box 2",
        dropdownMenu = dropdown(box_params,
                                label = "Plot Options Box 2",
                                numericInput(inputId = "box2", label = "Value", min = 1, max = 5, value = 3)
        )
    )
  )
)

server <- function(input, output) { }

shinyApp(ui, server)

I get this: enter image description here

So this is the same of @akrun's output?


Here is a version which actually renders the dropdown menu (The box() function doesn't have a dropdownMenu argument as @DJC's example code suggests):

result

library(shiny)
library(shinydashboard)
library(shinyWidgets)

box_params <- list(icon = icon("cogs"), 
                   width = "400px")

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    box(title = "Box 1",
        do.call(dropdown, c(box_params, 
                            list(label = "Plot Options Box 1",
                                 numericInput(inputId = "box1", label = "Value", min = 1, max = 5, value = 3))))
    ),
    box(title = "Box 2",
        dropdown(
          icon = icon("cogs"), 
          width = "400px",
          label = "Plot Options Box 2",
          numericInput(inputId = "box2", label = "Value", min = 1, max = 5, value = 3)
          
        )
    )
  )
)

server <- function(input, output) {}

shinyApp(ui, server)