The STORENUMBER filters the data and renders the map and table below, but the DMA doesn't. Does subset() work differently on factors than integers in server.r?
data
STORENUMBER = c(123,456)
DMA = c("LA","SD")
LATITUDE = c(130, 132)
LONGITUDE = c(30,35)
locations = data.frame(STORENUMBER, DMA, LATITUDE, LONGITUDE)
ui.r :
tabItem(tabName = "control",
fluidPage(
titlePanel("Control Center"),
fluidRow(
# the Stores are integers
column(6,
helpText("Test Stores"),
# test stores
selectInput("testStores",
label ="Test Stores",
choices = as.vector(unique(locations$STORENUMBER)),
selected = NULL,
multiple = TRUE)
),
# the DMAs are factors
column(6,
helpText("Test DMA"),
selectInput("tDMA",
label ="Test DMAs",
choices = as.vector(unique(locations$DMA)),
selected = NULL,
multiple = TRUE)
) #column
), #fluidRow
fluidRow(
titlePanel("Map"),
leafletOutput("map"),
p(),
actionButton("recalc", "New points")
) ,
fluidRow(
titlePanel("Test Store Table"),
column(12,
DT::dataTableOutput("tableteststores")
)
)
) #fluidPage
)
Here is the server.r script showing the subset() function.
server.r:
shinyServer(function(input, output){
# not sure why DMA isn't working
tstores <- reactive({
subset(locations, DMA %in% input$tDMA | STORENUMBER %in% input$testStores)
})
# table of locations
output$tableteststores <- DT::renderDataTable(DT::datatable(
data <- as.data.frame(tstores())
))
# map
output$map <- renderLeaflet({
leaflet() %>%
addProviderTiles("Stamen.TonerLite",
options = providerTileOptions(nonWrap = TRUE)
) %>%
addMarkers(data = tstores())
})
})