0

I am developping an app using R shiny where a reactive plot wil be outputed based on a certain filtration .But my problem is how to replace that plot with another one that using nearpoints observent or whateverelse.Below the code of a similar app(diffrence here is that data not filtrated like in my app where i used reactive for plot since the user filter the data as much as he wants and get correspeendent plot).

    data<-mpg  
                                              
output$p1<-reactive({    ggplot( data, aes(x = displ, y = cty)) + 
      geom_point(size = 7, colour = "#EF783D", shape = 17) +
      geom_line(color = "#EF783D") +
            ggtitle(paste("Insights : ", na.omit(filters$manufacturer), na.omit(filters$model), na.omit(filters$displ), na.omit(filters$year), sep = ", ")))})

observeEvent(input$plot_click,
    
    { a<- nearPoints(data,  input$plot_click, threshold = 10, maxpoints = 1,
                 addDist = F)$model
     
    
    
    
     dt<-dt[dt$model==a,]
     
    df<-data.frame("model"=dt$model,"displ"=dx$displ)
     ggplot(df, aes(x = model,y = displ,group = 1)) +
       geom_point()
     
    })
samir
  • 17
  • 5
  • SO closed your question, but the answer linked does not seem to be what you're asking. You can replace the plot by rerendering it. Try `output$p1 <- renderPlot({ ggplot(df, aes(x = model, y = displ, group = 1)) + geom_point() })` in the `observeEvent()` – guasi Jul 18 '22 at 16:14
  • @guasi it does not work though.peoplewho closed my closed do no understand that theew plot depend on click .i do notneed button – samir Jul 18 '22 at 17:35
  • Right. I suggest you edit your question to get it re-opened, change the title, highlight that you want to know how to replace a rendered plot using shiny's built-in plot click functionality. Highlight replace and plot click. I have a working solution. – guasi Jul 18 '22 at 17:51
  • @guasi i edited the title .let s see what happens – samir Jul 18 '22 at 18:05
  • @guasi i need that solution . please provide it to me in any way – samir Jul 19 '22 at 08:02
  • Since SO did not re-open your question, you may want to open a new question with a more concise title "How to replace a rendered plot with its own plot_click info in R Shiny" and re-write the problem to be more clear of what you want. More importantly, the new question should contain a complete reproducible shiny app that runs without errors but has the problem of not replacing the plot. – guasi Jul 19 '22 at 08:32
  • @guasi ok .When i am done with it ,i will tell you immediatley . – samir Jul 19 '22 at 10:11
  • @guasi this is the new post:https://stackoverflow.com/questions/73049410/how-to-replace-a-rendered-plot-with-its-own-plot-click-info-in-r-shiny – samir Jul 20 '22 at 09:49

0 Answers0