STORENUMBERはデータをフィルタリングし、下のマップとテーブルをレンダリングしますが、DMAはそうしません。サブセット()は、server.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())
})
})
テストデータを提供していないので、この問題は[再現可能]ではありません(http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。正確には「レンダリングしない」という意味ですか?エラーが発生していますか?選択したDMAの値が表示されているのか、数値が表示されていますか? – MrFlick
テストデータを追加しましたので、再現性があります。私はフォームフィールドに入力オブジェクトを見ることができますが、DMAを選択すると、マップオブジェクトとタブレットストアのオブジェクトはデータを返しません。 STORENUMBERを選択すると、マップとタブレットストアがオブジェクトを返します。したがって、subset()関数は整数STORENUMBERに対して機能しますが、要因DMAでは機能しません。あなたの思考に開放されています。ありがとう。 – JL82559
あなたが提供したコードで何らかのエラーを複製することはできません。 DMAによるフィルタリングはうまくいくようです。 – MrFlick