I am new to shiny, and I am creating an app that manages a reactive dataframe that allows selecting among a set of variables (PHENOTYPES) obtained in a data frame with missing values that I don't want to have plotted using leaflet.
What I am looking for is a way to filter out the NA values, so they are not plotted.
*****This question has also been posted on the shiny google group. I will erase either post once it is resolved and synthetize in one post any feedback so it does not become redundant:
https://groups.google.com/forum/#!topic/shiny-discuss/eLVf2Y50MDY
Thank you for your help.
Here is my R.server
shinyServer(function(input, output) {
output$map <- renderLeaflet({
print('render map')
leaflet(FULL) %>%
addSearchOSM(options = searchOSMOptions(position = 'topleft', zoom = 5)) %>%
addProviderTiles("OpenStreetMap.Mapnik", group = "OpenStreetmap") %>%
addProviderTiles("Esri.WorldImagery", group = "Esri.WorldImagery") %>%
setView(lng = 0, lat = 50, zoom = 2) %>%
addLayersControl(baseGroups = c('Esri.WorldImagery',"OpenStreetmap"),
options = layersControlOptions(collapsed = TRUE, autoZIndex = F, position = 'bottomleft' ))
})
df <- datasets[['FULL']]
makeReactiveBinding('df')
df <- reactive({ ####### This bit was added to sort this problem based
if (!is.null(input$yvar)){ ####### on advise on this thread, but It
out <- data %>% ######## stops the app. The app works if I remove this, only
filter(df == input$yvar, ######## that with the undesired NAs
!is.na(value)) ######
return(out) #######
} ###########
}) ##########
observeEvent(input$makeReactiveBinding,{
print('dataset')
leafletProxy('map')%>%clearShapes()
df <<- datasets[[input$dataset]]
i.active <<- NULL
})
coords <- reactive({
print('coords')
crds <- data.frame(coordinates(df))
leafletProxy('map')%>%fitBounds(lng1=min(crds[,1]),lng2=max(crds[,1]),
lat1=min(crds[,2]),lat2=max(crds[,2]))
crds
})
output$xvar <- renderUI(selectInput('color',label='Phenotype',choices = list("Phenotype A" =c("Variable AA", "Variable BB"), "Phenotype B"=c("Variable CC", "Variable DD")))
xVar <- reactive({
print('xVar')
if(is.null(input$xvar)) return(names(df)[1])
xvar_ <<- input$xvar
input$xvar})
xVar <- reactive({
print('colVar')
if(is.null(input$color)) return(names(df)[2])
input$color})
colorData <- reactive({
print(names(input))
print('colData')
df1 <- isolate(df@data)
df1[,xVar()]})
colorpal <- reactive(colorNumeric(input$pal, colorData()))
pal <- reactive({colorpal()(colorData())})
observe({
print('update map size/opa/color')
x <- coords()[,1]
y <- coords()[,2]
leafletProxy('map')%>%
addCircleMarkers(lng=x,fillColor = pal(),
lat=y,
stroke = F,
layerId = as.character(1:length(x)),
radius = input$size/10,
color = 'blue',
fillOpacity = 1)
})
mapData <- reactive({
print('mapdata')
mb <- input$map_bounds
if(is.null(mb))
return(1)
if(nrow(coords())!=nrow((ggvisdf())))
return(1)
as.numeric(coords()[,1]>mb$west&coords() [,1]<mb$east&
coords()[,2]>mb$south&coords()[,2]<mb$north)+0.1
})})})