how to clear the previous charts in reactive plots

i am using the stored procedure from ms SQL server but created it such a way to generate the reprex.
what i really wanna do, there are two categories on single pie-chart when i click on each slice, plots the different charts.let's say when i click on the position 1, it renders the barchart, then sub-barchart and so on, but when i click on position 0, it renders another barchart coupled with it, then it's sub-bar charts renders all the way down below, so how to clear the child-charts when another parent-chart is clicked and render its own chart on that very place.
how to get it done, i have tried to clear them through action-button but it won't work for this case as i wanna render them on that very place where previous charts from another parent were rendered.
i know, it's kinda complicated the way, i am explaining it, but i don't know how to put this problem in words.

for clarity plott 3 must be cleared and replaced with plott5 rather than rendering or plotting the chart all the way down there, how to use observe or reactive to make it happen.

library(shinyjs)
library(plotly)
library(shinydashboard)
library(shinycssloaders)
library(shiny)
library(dplyr)
library(DT)
library(tidyr)
library(shinycustomloader) 
library(tibble)
library(datapasta)

COL = c("#293a80","#39375b","#6915cf","#4b8e8d","#d55252","#293462","#940a37","#f54291","#f0134d","#b22222","#3c4245","#5d1451","#3c3d47")


ui<- fluidPage(
  fluidRow(column(width=12,
                  withLoader(plotlyOutput("plott1"),type = "html",loader = "loader4"))),
  fluidRow(column(width=12,
                  withLoader(plotlyOutput("plott2"),type = "html",loader = "loader1"))),
  fluidRow(column(width=12,
                  withLoader(plotlyOutput("plott3")))),
  fluidRow(column(width=12,
                  withLoader(plotlyOutput("plott4")))),
  fluidRow(column(width=12,
                  withLoader(plotlyOutput("plott5"))))
  )

server<- function(input,output)
  
{
  output$plott1 <- renderPlotly({
    sp1<-tibble::tribble(
      ~DID, ~DistrictName, ~BlockName, ~CenterName, ~TotRaj, ~TotOtherState, ~StateCode,
      76,       "state",     "null",      "null", 7656454,        5645345,     "null"
    )
    
    
    ds <- data.frame(labels = c("Rajasthan","Other_State"),
                     values = c(sp1$TotRaj,sp1$TotOtherState)
    )
    
    plot_ly(ds, labels = ~labels, values = ~values,type = 'pie',source ='listenhere1',
            textposition = 'inside',
            textinfo = 'label+percent',
            insidetextfont = list(color = '#FFFFFF'),
            marker = list(colors = c('#5d1451','#745c97'),
                          line = list(color =colors , width = 1)),showlegend = FALSE) %>% 
      layout(
        xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
        yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
  }) 
  
  output$plott2 <- renderPlotly({
    s <- event_data("plotly_click", source = "listenhere1")
    req(!is.null(s))
    
    if(s$pointNumber == 0){
      
      sp2<-tibble::tribble(
        ~DID, ~DistrictName, ~BlockName, ~CenterName, ~TotRaj, ~TotOtherState, ~StateCode,
        101,           "a",     "null",      "null",  564534,         564534,     "null",
        201,           "b",     "null",      "null",  675645,         765645,     "null",
        301,           "c",     "null",      "null",  765645,         786756,     "null",
        401,           "d",     "null",      "null",  987656,         764534,     "null",
        501,           "e",     "null",      "null",  675645,         543423,     "null",
        601,           "f",     "null",      "null",  765434,         231234,     "null",
        701,           "g",     "null",      "null",  564534,         763423,     "null",
        801,           "h",     "null",      "null",  234565,         567876,     "null",
        901,           "i",     "null",      "null",  985646,         876345,     "null",
        102,           "j",     "null",      "null",  876754,         453675,     "null",
        202,           "k",     "null",      "null",  876756,         876754,     "null"
      )
      
      layout <- list(
        font = list(size = 12),
        title = " District-Wise",
        xaxis = list(title = "district"),
        yaxis = list(title = "records",automargin = TRUE)
      )
      
      p <- plot_ly(sp2, x = sp2$DistrictName, y = sp2$TotRaj, type = 'bar', name = '',source = 'link3',key = ~paste(sp2$DID, sep = ""),marker = list(color = '#baabda')) %>%
        add_trace(y = sp2$TotOtherState, name = 'Other_State',marker = list(color = '#58508d')) %>%
        layout(yaxis = list(title = ''), barmode = 'stack')
    }
    else {
      sp2<-tibble::tribble(
        ~DID, ~DistrictName, ~BlockName, ~CenterName, ~TotRaj, ~TotOtherState, ~StateCode,
        101,           "a",     "null",      "null",  564534,         564534,     "null",
        201,           "b",     "null",      "null",  675645,         765645,     "null",
        301,           "c",     "null",      "null",  765645,         786756,     "null",
        401,           "d",     "null",      "null",  987656,         764534,     "null",
        501,           "e",     "null",      "null",  675645,         543423,     "null",
        601,           "f",     "null",      "null",  765434,         231234,     "null",
        701,           "g",     "null",      "null",  564534,         763423,     "null",
        801,           "h",     "null",      "null",  234565,         567876,     "null",
        901,           "i",     "null",      "null",  985646,         876345,     "null",
        102,           "j",     "null",      "null",  876754,         453675,     "null",
        202,           "k",     "null",      "null",  876756,         876754,     "null"
      )
      
      tablename=rowSums(cbind(sp2$TotRaj,sp2$TotOtherState),na.rm=TRUE)
      
      layout <- list(
        font = list(size = 12),
        title = " Other-State",
        xaxis = list(title = "RECORDS"),
        yaxis = list(title ="STATES" ,automargin = TRUE)
      )
      
      p <- plot_ly(sp2, colors = COL, marker = list(color = COL),source = 'linkhere',orientation='h',key = ~paste(sp2$DID, sep = "")) %>%
        add_trace( x =sp2$TotOtherState,y = sp2$StateName,name = "states",type = 'bar') %>%
        layout( font = layout$font, title = layout$title, xaxis = layout$xaxis, yaxis = layout$yaxis)
    }
  })
  
  output$plott3 <- renderPlotly({
    
    d<-event_data('plotly_click',source = 'link3')
    if(is.null(d)==F){
      sp3<-data.frame(stringsAsFactors=FALSE,
                      DID = c(101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101),
                      DistrictName = c("a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a"),
                      BlockName = c("aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh",
                                    "iii", "jjj", "kkk"),
                      CenterName = c("null", "null", "null", "null", "null", "null", "null",
                                     "null", "null", "null", "null"),
                      TotRaj = c(564534, 675645, 765645, 987656, 675645, 765434, 564534,
                                 234565, 985646, 876754, 876756),
                      TotOtherState = c(564534, 765645, 786756, 764534, 543423, 231234, 763423,
                                        567876, 876345, 453675, 876754),
                      StateCode = c("null", "null", "null", "null", "null", "null", "null",
                                    "null", "null", "null", "null"),
                      CID = c("c01", "c02", "c03", "c04", "c05", "c06", "c07", "c08",
                              "c09", "c10", "c11")
      )
      
      p <- plot_ly(sp3, x = sp3$BlockName, y = sp3$TotRaj, type = 'bar', name = '',key = ~paste(sp3$DID,sep = ""), source = 'link1',marker = list(color = '#537ec5')) %>%
        add_trace(y = sp3$TotOtherState, name = 'other-state',marker = list(color = '#57007e')) %>%
        layout(yaxis = list(title = 'sonography block_level'),xaxis = list(title = 'Block name'), barmode = 'group',title='')}
    else{
      return(NULL)
    }
    
  })
  
  output$plott4 <- renderPlotly({
    d<-event_data('plotly_click',source = 'link1')
    if(is.null(d)==F){
      sp4<-data.frame(stringsAsFactors=FALSE,
                      DID = c(101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101),
                      DistrictName = c("a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a"),
                      BlockName = c("aaa", "aaa", "aaa", "aaa", "aaa", "aaa", "aaa", "aaa",
                                    "aaa", "aaa", "aaa"),
                      CenterName = c("abc", "bac", "dac", "efc", "ghc", "hic", "jkl", "mnl",
                                     "lkj", "ghj", "kjh"),
                      TotRaj = c(2345, 2343, 6754, 7656, 8767, 6756, 4534, 5678, 6756,
                                 5434, 9876),
                      TotOtherState = c(4532, 2345, 3456, 4567, 9845, 9876, 6756, 5645, 4534,
                                        5645, 7865),
                      StateCode = c("null", "null", "null", "null", "null", "null", "null",
                                    "null", "null", "null", "null"),
                      CID = c("c01", "c02", "c03", "c04", "c05", "c06", "c07", "c08",
                              "c09", "c10", "c11")
      )
      
      
      p <- plot_ly(sp4, x = sp4$TotRaj, y =sp4$CenterName , type = 'bar', name = 'rajasthan',key = ~paste(sp4$CID, sep = ""),source = "hey",
                   marker = list(color = '#1a3e59',
                                 line = list(color = 'rgba(246, 78, 139, 1.0)'))) %>%
        add_trace(x = sp4$TotFormFOtherState, name = 'other-state',
                  marker = list(color = '#baabda',
                                line = list(color = 'rgba(58, 71, 80, 1.0)'))) %>%
        layout(barmode = 'stack',
               xaxis = list(title = "Centre Data"),
               yaxis = list(title ="Centre Name"))}
    else{return(NULL)}
  })
  
  output$plott5 <- renderPlotly({
    s <- event_data("plotly_click", source = "linkhere")
    req(!is.null(s))
      
      sp5<-tibble::tribble(
               ~DID, ~DistrictName, ~BlockName, ~CenterName, ~TotRaj, ~TotOtherState, ~StateCode,   ~CID, ~StateName,
             "null",        "null",     "null",       "nul",   "nul",           4532,          1, "null",    "alpha",
             "null",        "null",     "null",       "nul",   "nul",           2345,          2, "null",     "beta",
             "null",        "null",     "null",       "nul",   "nul",           3456,          3, "null",     "gama",
             "null",        "null",     "null",       "nul",   "nul",           4567,          4, "null",    "theta",
             "null",        "null",     "null",       "nul",   "nul",           9845,          5, "null",      "abn",
             "null",        "null",     "null",       "nul",   "nul",           9876,          6, "null",      "mnb",
             "null",        "null",     "null",       "nul",   "nul",           6756,          7, "null",      "vbg",
             "null",        "null",     "null",       "nul",   "nul",           5645,          8, "null",      "hjg",
             "null",        "null",     "null",       "nul",   "nul",           4534,          9, "null",      "klj",
             "null",        "null",     "null",       "nul",   "nul",           5645,         10, "null",      "ghj",
             "null",        "null",     "null",       "nul",   "nul",           7865,         11, "null",      "jhg"
             )

      
      layout <- list(
        font = list(size = 12),
        title = " District-Wise",
        xaxis = list(title = "district"),
        yaxis = list(title = "records",automargin = TRUE)
      )
      
      p <- plot_ly(sp5, x = sp5$StateName, y = sp5$TotOtherState, type = 'bar', name = '',source = 'link3',key = ~paste(sp5$DID, sep = ""),marker = list(color = COL))
        
  })
  
  
}



runApp(list(ui = ui, server = server), launch.browser = TRUE)

i wanna render or plot chart 5 in the place of chart 3. 1.when we click on the pie chart it renders the different charts on each slice of it, as i have taken the position as a condition to plot the two charts on the same plot. 2.what i wanna do is to render the chart 5 in plott3 as per condition when i click on position 0,it renders a chart and when i click on it, it renders to another and same for the position 1 but when position 1 renders a chart and i click on that chart, instead of plott5, i wanna render it on that same place as (plott3) as soon as the chart above is clicked. 3. In simple words, i want chart 3 there and chart 5 also there as per reactive or plotly_click event occur.

chart 3 and chart 5 on plott3 as per the plotly_click event occur

library(shinyjs)
library(plotly)
library(shinydashboard)
library(shinycssloaders)
library(shiny)
library(dplyr)
library(DT)
library(tidyr)
library(shinycustomloader) 
library(tibble)
library(datapasta)

COL = c("#293a80","#39375b","#6915cf","#4b8e8d","#d55252","#293462","#940a37","#f54291","#f0134d","#b22222","#3c4245","#5d1451","#3c3d47")


ui<- fluidPage(
  fluidRow(column(width=12,
                  withLoader(plotlyOutput("plott1"),type = "html",loader = "loader4"))),
  fluidRow(column(width=12,
                  withLoader(plotlyOutput("plott2"),type = "html",loader = "loader1"))),
  fluidRow(column(width=12,
                  withLoader(plotlyOutput("plott3")))),
  fluidRow(column(width=12,
                  withLoader(plotlyOutput("plott4")))),
  fluidRow(column(width=12,
                  withLoader(plotlyOutput("plott5"))))
  )

server<- function(input,output)

{
  output$plott1 <- renderPlotly({
    sp1<-tibble::tribble(
      ~DID, ~DistrictName, ~BlockName, ~CenterName, ~TotRaj, ~TotOtherState, ~StateCode,
      76,       "state",     "null",      "null", 7656454,        5645345,     "null"
    )


    ds <- data.frame(labels = c("Rajasthan","Other_State"),
                     values = c(sp1$TotRaj,sp1$TotOtherState)
    )

    plot_ly(ds, labels = ~labels, values = ~values,type = 'pie',source ='listenhere1',
            textposition = 'inside',
            textinfo = 'label+percent',
            insidetextfont = list(color = '#FFFFFF'),
            marker = list(colors = c('#5d1451','#745c97'),
                          line = list(color =colors , width = 1)),showlegend = FALSE) %>% 
      layout(
        xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
        yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
  }) 

  output$plott2 <- renderPlotly({
    s <- event_data("plotly_click", source = "listenhere1")
    req(!is.null(s))

    if(s$pointNumber == 0){

      sp2<-tibble::tribble(
        ~DID, ~DistrictName, ~BlockName, ~CenterName, ~TotRaj, ~TotOtherState, ~StateCode,
        101,           "a",     "null",      "null",  564534,         564534,     "null",
        201,           "b",     "null",      "null",  675645,         765645,     "null",
        301,           "c",     "null",      "null",  765645,         786756,     "null",
        401,           "d",     "null",      "null",  987656,         764534,     "null",
        501,           "e",     "null",      "null",  675645,         543423,     "null",
        601,           "f",     "null",      "null",  765434,         231234,     "null",
        701,           "g",     "null",      "null",  564534,         763423,     "null",
        801,           "h",     "null",      "null",  234565,         567876,     "null",
        901,           "i",     "null",      "null",  985646,         876345,     "null",
        102,           "j",     "null",      "null",  876754,         453675,     "null",
        202,           "k",     "null",      "null",  876756,         876754,     "null"
      )

      layout <- list(
        font = list(size = 12),
        title = " District-Wise",
        xaxis = list(title = "district"),
        yaxis = list(title = "records",automargin = TRUE)
      )

      p <- plot_ly(sp2, x = sp2$DistrictName, y = sp2$TotRaj, type = 'bar', name = '',source = 'link3',key = ~paste(sp2$DID, sep = ""),marker = list(color = '#baabda')) %>%
        add_trace(y = sp2$TotOtherState, name = 'Other_State',marker = list(color = '#58508d')) %>%
        layout(yaxis = list(title = ''), barmode = 'stack')
    }
    else {
      sp2<-tibble::tribble(
        ~DID, ~DistrictName, ~BlockName, ~CenterName, ~TotRaj, ~TotOtherState, ~StateCode,
        101,           "a",     "null",      "null",  564534,         564534,     "null",
        201,           "b",     "null",      "null",  675645,         765645,     "null",
        301,           "c",     "null",      "null",  765645,         786756,     "null",
        401,           "d",     "null",      "null",  987656,         764534,     "null",
        501,           "e",     "null",      "null",  675645,         543423,     "null",
        601,           "f",     "null",      "null",  765434,         231234,     "null",
        701,           "g",     "null",      "null",  564534,         763423,     "null",
        801,           "h",     "null",      "null",  234565,         567876,     "null",
        901,           "i",     "null",      "null",  985646,         876345,     "null",
        102,           "j",     "null",      "null",  876754,         453675,     "null",
        202,           "k",     "null",      "null",  876756,         876754,     "null"
      )

      tablename=rowSums(cbind(sp2$TotRaj,sp2$TotOtherState),na.rm=TRUE)

      layout <- list(
        font = list(size = 12),
        title = " Other-State",
        xaxis = list(title = "RECORDS"),
        yaxis = list(title ="STATES" ,automargin = TRUE)
      )

      p <- plot_ly(sp2, colors = COL, marker = list(color = COL),source = 'linkhere',orientation='h',key = ~paste(sp2$DID, sep = "")) %>%
        add_trace( x =sp2$TotOtherState,y = sp2$StateName,name = "states",type = 'bar') %>%
        layout( font = layout$font, title = layout$title, xaxis = layout$xaxis, yaxis = layout$yaxis)
    }
  })

  output$plott3 <- renderPlotly({

    d<-event_data('plotly_click',source = 'link3')
    if(is.null(d)==F){
      sp3<-data.frame(stringsAsFactors=FALSE,
                      DID = c(101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101),
                      DistrictName = c("a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a"),
                      BlockName = c("aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh",
                                    "iii", "jjj", "kkk"),
                      CenterName = c("null", "null", "null", "null", "null", "null", "null",
                                     "null", "null", "null", "null"),
                      TotRaj = c(564534, 675645, 765645, 987656, 675645, 765434, 564534,
                                 234565, 985646, 876754, 876756),
                      TotOtherState = c(564534, 765645, 786756, 764534, 543423, 231234, 763423,
                                        567876, 876345, 453675, 876754),
                      StateCode = c("null", "null", "null", "null", "null", "null", "null",
                                    "null", "null", "null", "null"),
                      CID = c("c01", "c02", "c03", "c04", "c05", "c06", "c07", "c08",
                              "c09", "c10", "c11")
      )

      p <- plot_ly(sp3, x = sp3$BlockName, y = sp3$TotRaj, type = 'bar', name = '',key = ~paste(sp3$DID,sep = ""), source = 'link1',marker = list(color = '#537ec5')) %>%
        add_trace(y = sp3$TotOtherState, name = 'other-state',marker = list(color = '#57007e')) %>%
        layout(yaxis = list(title = 'sonography block_level'),xaxis = list(title = 'Block name'), barmode = 'group',title='')}
    else{
      return(NULL)
    }

  })

  output$plott4 <- renderPlotly({
    d<-event_data('plotly_click',source = 'link1')
    if(is.null(d)==F){
      sp4<-data.frame(stringsAsFactors=FALSE,
                      DID = c(101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101),
                      DistrictName = c("a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a"),
                      BlockName = c("aaa", "aaa", "aaa", "aaa", "aaa", "aaa", "aaa", "aaa",
                                    "aaa", "aaa", "aaa"),
                      CenterName = c("abc", "bac", "dac", "efc", "ghc", "hic", "jkl", "mnl",
                                     "lkj", "ghj", "kjh"),
                      TotRaj = c(2345, 2343, 6754, 7656, 8767, 6756, 4534, 5678, 6756,
                                 5434, 9876),
                      TotOtherState = c(4532, 2345, 3456, 4567, 9845, 9876, 6756, 5645, 4534,
                                        5645, 7865),
                      StateCode = c("null", "null", "null", "null", "null", "null", "null",
                                    "null", "null", "null", "null"),
                      CID = c("c01", "c02", "c03", "c04", "c05", "c06", "c07", "c08",
                              "c09", "c10", "c11")
      )


      p <- plot_ly(sp4, x = sp4$TotRaj, y =sp4$CenterName , type = 'bar', name = 'rajasthan',key = ~paste(sp4$CID, sep = ""),source = "hey",
                   marker = list(color = '#1a3e59',
                                 line = list(color = 'rgba(246, 78, 139, 1.0)'))) %>%
        add_trace(x = sp4$TotFormFOtherState, name = 'other-state',
                  marker = list(color = '#baabda',
                                line = list(color = 'rgba(58, 71, 80, 1.0)'))) %>%
        layout(barmode = 'stack',
               xaxis = list(title = "Centre Data"),
               yaxis = list(title ="Centre Name"))}
    else{return(NULL)}
  })

  output$plott5 <- renderPlotly({
    s <- event_data("plotly_click", source = "linkhere")
    req(!is.null(s))

      sp5<-tibble::tribble(
               ~DID, ~DistrictName, ~BlockName, ~CenterName, ~TotRaj, ~TotOtherState, ~StateCode,   ~CID, ~StateName,
             "null",        "null",     "null",       "nul",   "nul",           4532,          1, "null",    "alpha",
             "null",        "null",     "null",       "nul",   "nul",           2345,          2, "null",     "beta",
             "null",        "null",     "null",       "nul",   "nul",           3456,          3, "null",     "gama",
             "null",        "null",     "null",       "nul",   "nul",           4567,          4, "null",    "theta",
             "null",        "null",     "null",       "nul",   "nul",           9845,          5, "null",      "abn",
             "null",        "null",     "null",       "nul",   "nul",           9876,          6, "null",      "mnb",
             "null",        "null",     "null",       "nul",   "nul",           6756,          7, "null",      "vbg",
             "null",        "null",     "null",       "nul",   "nul",           5645,          8, "null",      "hjg",
             "null",        "null",     "null",       "nul",   "nul",           4534,          9, "null",      "klj",
             "null",        "null",     "null",       "nul",   "nul",           5645,         10, "null",      "ghj",
             "null",        "null",     "null",       "nul",   "nul",           7865,         11, "null",      "jhg"
             )


      layout <- list(
        font = list(size = 12),
        title = " District-Wise",
        xaxis = list(title = "district"),
        yaxis = list(title = "records",automargin = TRUE)
      )

      p <- plot_ly(sp5, x = sp5$StateName, y = sp5$TotOtherState, type = 'bar', name = '',source = 'link3',key = ~paste(sp5$DID, sep = ""),marker = list(color = COL))

  }) }
runApp(list(ui = ui, server = server), launch.browser = TRUE)

both are different topics

  1. render the multiple chart on same plotlyoutput
    2.when we click on a chart ,it renders another,and so on but chart one has two categories when we click on that,it doesn't clear the previous charts ,it is still where it was earlier

how come ,both are the same topic

I think you can achieve both these tasks by adding additional conditions to your if and else statements as you render each plot.

Your examples are pretty complex and so it's hard to dive in, but you can monitor click events given different inputs iwth the following in server added,

 output$click <- renderPrint({
        
        click_listenhere1 <- event_data("plotly_click", source = "listenhere1")
        if (is.null(click_listenhere1)) result <- list("click_listenhere1 Click events appear here (double-click to clear)") else
        {result <- list(list("click_listenhere1", click_listenhere1))}

        click_l1<-event_data('plotly_click',source = 'link1')
        if (is.null(click_l1)) result <- list(result, "click_l1 Click events appear here (double-click to clear)") else
        {result <- list(result, list("click_l1", click_l1))}
        
        click_l3<-event_data('plotly_click',source = 'link3')
        if (is.null(click_l3)) result <- list(result, "click_l3 Click events appear here (double-click to clear)") else
        {result <- list(result, list("clickl3", click_l3))}
        
        click_linkhere <- event_data("plotly_click", source = "linkhere")
        if (is.null(click_linkhere)) result <- list(result, "click_linkhere Click events appear here (double-click to clear)") else
        {result <- list(result, list("click_linkhere", click_linkhere))}
        
        result
    })

and the following to ui added

,
    fluidRow(column(width=12,
                    withLoader(verbatimTextOutput("click")))),

As you click different combinations of plots, you can see how these click event values change. And then apply whatever conditions you desire to show or hide each plots.


Just a note on reproducible examples, that's a bunch for making so much progress and offering up working reproducible examples of the problem you're facing. I know that can be, particularly since you've suggested you're newer to shiny, and since your porting this from an even more complex app

But these do highlight the benefits of working on the minimal part of a minimal reproducible example. Because these plots involve so much data, and the source naming convention is difficult to follow, it makes it really hard to just take your code and offer a solution.

thanks for your help but what i really wanna do is to clear the previous charts when parent chart is clicked again,let's say there are two parts of parent chart given in above pie chart.when part1 is clicked it renders it's child charts ,when i click on that child chart it renders it's child chart and son on ,but when i click on another part of parent chart it replaces it's child child due to direct condition applied to it with (if and else) but child chart level 2 is still there and when pie chart is clicked again ,it has it's own charts that need to be replaced or plotted on that same place but this task can't be achieved if previous chart of another category is still there.
i know,it's kinda confusing and i tried to create the above reprex as simple as i could but this scenario is too complex to put it into simplest form than that of above.
i hope,you would understand what i am trying to explain here,don't go after my words as it seems to make it more complex than it really is.

This is cross-posted on SO


when i don't get any reply from one site then only i post it to another,i didn't know ,it is considered against the rule.
and when i get the answer from one site then i post it to another also to avoid any kind of unnecessary work on problem that has been taken care of or solved.

you can check my any post here if i get answer from stackoverflow ,i upload that here too or give link to that solution ,i don't get what's wrong with that.

i am kinda new to this,you can guide me through if i am wrong somehow

It's OK to cross post if you are not getting an answer on a reasonable time but we only ask you to follow the guidelines to do it.
The most important part would be to make it explicit and link to the other sites