Reactivity for pop-up according to the region selected

shiny
leaflet
shinydashboard

#1

Hi everyone,

Just started using shiny app. Have no background in CSS or HTML so I keep learning using youtube google etc. I’ve created a map for my work duties that is linked to three selectinputs made a popup value created reactivity between inputs and map itself. But the filtered value that comes from a subset (as far as I understood there is no term called filtering in shiny only “subsetting”). Popup value doesnt react to the location that I’ve chosen which in fact in available as character variable in my data frame. I would be really grateful if someone could help me. If available we can contact through e-mail. I am quite good in data manipulation and statistical analysis in R, i am assured it’s the best but shiny is a new challenge that I want to overcome. Many thanks in advance.

Here is the code:

library(xlsx)
library(readr)
library(bit64)
library(data.table)
library(dplyr)
library(lubridate)
library(readxl)
library(readstata13)
library(matrixStats)
library(ggplot2)
library(timeDate)
library(googleVis)
library(ggmap)
library(shiny)
library(shinydashboard)
library(leaflet)


setwd("C:/Users/NoHasanov/Desktop/N.Hasanov/ggmap")
ppo=as.data.table(readRDS("PPO.rds"))
ppo$latlong<-paste(ppo$lat, ppo$long, sep=":")
ppo=ppo[latlong!="NA:NA"]
ppo=ppo[Amount!="NA"]

#UI####
tp=c(unique(ppo$`Tariff Plan`))
trns=c(unique(ppo$`Type of Trns`))
month=c(unique(ppo$Month))
ui=shinyUI(dashboardPage(
  dashboardHeader(title = "Product Performance Overview",titleWidth = 330),
  dashboardSidebar(selectInput(inputId = "trns",label="Type of Transaction",trns,selected = "Charges",multiple = F,selectize = T),
                   selectInput(inputId = "month",label="Month",month,selected = "Sep",multiple = F,selectize = T), 
                   selectInput(inputId = "tp",label="Tariff Plan",tp,selected = "Unique",multiple = F,selectize = T)
                   
  ),
  dashboardBody(leafletOutput("map")),
    
  skin="black"
))
#SERVER####
server=function(input, output,session) {
  output$map=renderLeaflet({leaflet() %>% addTiles() %>%
      setView(47.5769,40.1431,zoom=7,options=list(region="AZ",resolution="provinces"))%>%
    addProviderTiles(providers$Stamen.TonerLite )
  })
  observeEvent({input$trns
                input$month
                input$trns}, {
      
      if(input$trns != "" &input$month != "" &input$tp != "" )
      {
        leafletProxy("map") %>% clearShapes()
        dataset=ppo[`Type of Trns` == paste(input$trns)& ppo$`Tariff Plan`==paste(input$tp) & ppo$Month==paste(input$month)]
        leafletProxy("map")%>% addCircles(lng = dataset$long, lat = dataset$lat,weight = 5, radius = sqrt(dataset$Amount), popup = paste(dataset$Region,"<br>",round(sum(dataset$Amount),digits=2)))
      }
    })
}

shinyApp(ui=ui,server=server)