The problem is that the new UI created and the new spectrumInput work well while the previous spectrumInput work bad.The color can not be selected.
library(shiny)
library(shinyWidgets)
library(RColorBrewer)
palette_set<-c(
list(brewer.pal(11,"BrBG")[-c(6,7)]),
list(brewer.pal(11,"PuOr")[-c(6,7)]),
list(brewer.pal(11,"PRGn")[-c(6,7)]),
list(brewer.pal(11,"PiYG")[-c(6,7)]),
list(brewer.pal(11,"RdBu")[-c(6,7)]),
list(brewer.pal(11,"RdGy")[-c(6,7)]),
list(brewer.pal(11,"RdYlBu")[-c(6,7)]),
list(brewer.pal(11,"RdYlGn")[-c(6,7)]),
list(brewer.pal(11,"Spectral")[-c(6,7)])
)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
actionButton('addBtn', 'Add input Set'),
tags$div(id='inputList')
),
mainPanel()
)
)
server <- function(input, output,session) {
observeEvent(input$addBtn, {
nr <- input$addBtn
id <- paste0("input",input$addBtn)
insertUI(
selector = '#inputList',
ui=div(
id = paste0("newInput",nr),
selectizeInput(
inputId = id,
choices = c("Stuff","to","input"),
selected = c("Stuff"),
label = "An Input:",
multiple = TRUE
),
spectrumInput(paste0("Scale_color",nr),paste0("color",nr),palette_set,selected ="steelblue",
options = list(`toggle-palette-more-text` = "more",
`toggle-palette-less-text` = "less",
`show-initial` ="true",
`show-input` ="true",
`show-buttons`="false",
`preferred-format`="rgb"
)),
actionButton(paste0('removeBtn',nr), 'Remove')
)
)
observeEvent(input[[paste0('removeBtn',nr)]],{
shiny::removeUI(
selector = paste0("#newInput",nr)
)
})
})
}
shinyApp(ui, server)