Insert UI by a bsbutton in R shiny. The UI would not insert when the button is clicked. Any help please?

108 views Asked by At

I am trying to create an interactive UI, which asks for more details as the user interacts with it. I have added a bsButton, which is supposed to insert more input options to collect more details, but the button is not inserting the UI when it is clicked. Any help or recommendations for the code? Thanks in advance.

ui <- shinyUI(  #UI
  dashboardPage( 
       fluidPage(  
         fluidRow(
            introBox(
                bsButton("pricing_request", #button to insert UI to collect more details
                         label = "Pricing Request", 
                         icon = icon("car-battery"), 
                         style = "success")
)))))

#serverpart

server <- function(input, output, session) {


observeEvent(input$pricing_request,{
insertUI(
selector = "#add",
where = "afterEnd",
ui = box(               #UI to be inserted
  bootstrapPage(
    div(style="float:right", actionButton("add_request", 
                                          label = "add option", 
                                          icon = icon("plus"), 
                                          style = "arial")),
    
    div(style="display:inline-block",
        textInput(
          inputId = "option_1",
          label = "Option",
          width = '350px',
          value = "insert option"))))
 )})}




             
    
       
1

There are 1 answers

0
Stéphane Laurent On BEST ANSWER

By writing

insertUI(
  selector = "#add",
  where = "afterEnd",
  ......

you request to add an UI after the HTML element whose id is add. But there's no such element in your app. If you add div(id = "add") somewhere in your app, that should work.