Note: I recognize that similar questions about passing function arguments as a list have been asked previously, but most solutions rely on using do.call ahead of the function name and I have not had any luck with that approach.
I have a simple dashboard with two boxes on it. I would like to store the dropdown menu parameters as a list to be used in other boxes. The specific parameters I would like to store are: icon, and width.
Below is a working version of the application without the dropdown parameters stored in a list:
library(shiny)
library(shinydashboard)
library(shinyWidgets)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(title = "Box 1",
dropdownMenu = dropdown(icon = icon("cogs"),
width = "400px",
label = "Plot Options Box 1",
numericInput(inputId = "box1", label = "Value", min = 1, max = 5, value = 3)
)
),
box(title = "Box 2",
dropdownMenu = 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)
What I would like to do is store the box parameters in a list like this:
box_params <- list(icon = icon("cogs"),
width = "400px")
And then to be able to call these parameters along these lines:
dropdown(box_params,
label = "Plot Options Box 1",
numericInput(inputId = "box1", label = "Value", min = 1, max = 5, value = 3))
>Solution :
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
