Dynamically plots out on the fly


how are we able to generate that kind of dynamic plots out in R Shiny using ggplot2 or plotly?
that is, users selects / deselects the data, then it will plot /remove plot accordingly on the same overlapping page.
Is this achievable in R Shiny in the first place?
I believe using some kind of reactive, it is possible, but with ggplot2 or plotly alone, are they sufficient?
Thanks for your input.

I have got some clue from this link: 17 Server-side linking with shiny | Interactive web-based data visualization with R, plotly, and shiny

library(shiny)
library(plotly)

ui <- fluidPage(
  selectizeInput(
    inputId = "cities", 
    label = "Select a city", 
    choices = unique(txhousing$city), 
    selected = "Abilene",
    multiple = TRUE
  ),
  plotlyOutput(outputId = "p")
)

server <- function(input, output, ...) {
  output$p <- renderPlotly({
    plot_ly(txhousing, x = ~date, y = ~median) %>%
      filter(city %in% input$cities) %>%
      group_by(city) %>%
      add_lines()
  })
}

shinyApp(ui, server)

But I would like to further enhance it by:
adding different colors to the plots, such that the color of the plot would the same as the color of the words highlighted in the "Select a City", is it possible? so that we know which plot belongs to which city..
any help would be greatly appreciated.
Thanks.