I'm trying to create a page to include and exclude boxes dynamically using boxDropdownItem from shinydashboardplus package, but the application is crashing, could someone help me please?
*Solutions using javascript are also welcome :)
Here my code:
shinyApp(
ui = dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
uiOutput("boxes")
)
),
server = function(input, output) {
rvs = reactiveValues(boxDropdownItem = list(), observers = list())
output$boxes <- renderUI({
for(i in 1:5) {
rvs$boxDropdownItem[[i]] =
column(width = 12,
box( id = paste("box",i),
title = paste("box",i),
width = 4,
status = NULL,
dropdownMenu = boxDropdown(
icon = icon("ellipsis-v"),
boxDropdownItem(id = paste0("del",i), "Delete")
)
)
)
}
rvs$observers = lapply(1:(length(rvs$boxDropdownItem)),function(i) {
observeEvent(input[[paste0("del",i)]],{
rvs$observers <- rvs$observers[-i]
rvs$boxDropdownItem <- rvs$boxDropdownItem[-i]
})
})
do.call(fluidRow, rvs$boxDropdownItem)
})
}
)
You need to first create the boxes as a
reactiveValues
object. Then you can control what you display inrenderUI
. I have shown here for 3 boxes. You can modify it to dynamic number. Try thisThe picture below shows box 2 deleted.