Created
August 17, 2018 13:06
-
-
Save DzmitryGB/6c840d245a6d77d8a462cb38b9ae0960 to your computer and use it in GitHub Desktop.
Shiny bug example: insertUI in a for loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| library(colourpicker) | |
| function(input,output,session) { | |
| counter <- reactiveValues(i = NULL) | |
| observeEvent(input$loadExample, { | |
| counter$i <- 2 | |
| }) | |
| observeEvent(counter$i, { | |
| colors = c("#7F7F7F","#00688B") | |
| if (!is.null(counter$i)) { | |
| for (i in 1:counter$i) { | |
| insertUI(selector='#ctrlDiv',where="beforeEnd",ui=HTML(paste0(" | |
| <div id='div",i,"' style='padding-top:30px;'> | |
| <div id='aDiv",i,"'> </div> | |
| <div id='bDiv",i,"'> </div> | |
| <div id='cDiv",i,"'> </div> | |
| </div>" | |
| ))) | |
| insertUI(selector=paste0('#aDiv',i),where="afterBegin",ui=selectInput( | |
| paste0('aInput',i),"input a",c(seq(1,i),NA),selected=i | |
| )) | |
| insertUI(selector=paste0('#bDiv',i),where="afterBegin",ui=checkboxInput( | |
| paste0('bInput',i),"input b",TRUE | |
| )) | |
| insertUI(selector=paste0('#cDiv',i),where="afterBegin",ui=colourInput( | |
| paste0('cInput',i),"input c",paste(colors[i]) | |
| )) | |
| } | |
| } | |
| }) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| fluidPage( | |
| sidebarLayout( | |
| sidebarPanel( | |
| actionButton("loadExample","Load Example"), | |
| div(id="ctrlDiv") | |
| ), | |
| mainPanel() | |
| ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment