I have 3 selectInput in my application. All have to be form in the insertUI. The first filter shall cmake changes in the 2nd and 2nd can make changes in 3rd. And How to avoid the duplicate insertUI being formed.
library(shiny)
library(shinyjs)
dt<- data.frame("location"=c("USA", "India", "UK", "India", "USA", "UK"), "Site"=c("google", "facebook", "microsoft", "Vodafone", "Airtel", "Aditya Birla"),
"Profit"=c("1000", "15000", "25000", "500", "250000", "410000"))
ui<- fluidPage(
titlePanel("Links"),
fluidRow(column( width = 8,
div(
uiOutput('item'),
actionButton("send", "Send")
)
)))
server<- function(input,output,session)
{
observeEvent(input$send,{
insertUI(selector = "#send", where = "beforeBegin",
ui=div(class="bubbles",
div(class="bubble",
wellPanel(
p("What is your preferred site?", tags$br(),
selectInput("location", "Location", choices =sort(unique(as.character(dt$location) ))
)
)))))
})
choice2<- reactive({
dt%>% filter(location==input$location)%>% pull("Site")
})
observeEvent(input$location, {
insertUI(selector = "#send", where = "beforeBegin",
ui=div(class="bubbles",
div(class="bubble",
wellPanel(
p("What is your preferred site?", tags$br(),
output$site<- renderUI({
selectInput("selection", "site", choices =sort(unique(as.character(choice2()) ))
)
})
)))))
})
choice3<- reactive({
dt%>% filter(location==input$location)%>% pull("Site")%>%
filter(Site==choice2())%>% pull(Profit)
})
observeEvent(input$selection, {
insertUI(selector = "#send", where = "beforeBegin",
ui=div(class="bubbles",
div(class="bubble",
wellPanel(
p("What is your preferred site?", tags$br(),
output$site<- renderUI({
selectInput("profit", "Profit", choices =sort(unique(as.character(choice3()) ))
)
})
)))))
})
}
shinyApp(ui,server)