0
STORENUMBER過濾數據並呈現下面的地圖和表格,但DMA沒有。 subset()的工作方式與server.r中的整數不同嗎?閃亮的r子集因子輸入
數據
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
)
這裏是表示該子集()函數server.r腳本。
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())
})
})
你還沒有提供任何測試數據,所以這個問題不是[reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。你究竟是什麼意思,它「不渲染」?你有錯誤嗎?您的選擇是顯示您期望的DMA值還是顯示您的數字? – MrFlick
增加了測試數據,現在可以重現。我可以在表單字段中看到輸入對象,但是當選擇DMA時,映射對象和tableteststores對象不會返回數據。當選擇STORENUMBER時,map和tableteststores會返回對象。所以看起來subset()函數對整數STORENUMBER起作用,但對於因子DMA不起作用。打開你的想法。謝謝。 – JL82559
我無法用您提供的代碼複製任何錯誤。通過DMA過濾似乎工作得很好。 – MrFlick