【发布时间】:2019-12-04 23:54:26
【问题描述】:
这个真的让我绕圈子。
我正在编写一个 R 脚本,该脚本加载一个数据帧并使用数据帧中的字段来填充selectizeInput 的分层集。例如。每个输入都代表前一个输入的子集。每个 SubRegion 包含多个 LCC,每个 LCC 包含多个 ENB,依此类推。
当用户在任何输入中选择一个值时,该值将用于过滤数据框,并且所有其他 selectizeInputs 都需要从过滤后的数据中更新。
第一个输入(SubRegionInput)似乎工作正常,但每次我尝试让它响应和/或过滤任何其他输入(例如,将input$LCCInput 添加到观察块)时,它们都会被填充几秒钟,然后空白。
我怀疑答案很简单和/或我正在做一些非常愚蠢的事情,但我是一个没有正式 R 培训的彻头彻尾的黑客,所以可能缺少一些非常基本的东西(如果很抱歉的话)。
以下是部分代码(抱歉,我无法将其全部包含在内,但这是为了工作,我无法分享我正在做的事情的细节)。
注意事项 当前的输出只是为了让我在开发这部分代码时可以看到发生了什么。 我现在知道它只设置为过滤一个值......我尝试做的所有事情都失败了,所以我包含了迄今为止我拥有的最实用的代码。
ui <- fluidPage(
# Application title
titlePanel("KPI DrillDown"),
# Sidebar with a slider input for number of bins
fluidRow(
selectizeInput("SubRegionInput", "SubRegion", SubRegionList ,selected = NULL, multiple = TRUE),
selectizeInput("LCCInput", "LCC", LCCList,selected = NULL, multiple = TRUE),
selectizeInput("ENBIDInput", "ENBID", ENBIDList,selected = NULL, multiple = TRUE),
selectizeInput("SiteNumInput", "SiteNumber", SiteNumberList,selected = NULL, multiple = TRUE),
selectizeInput("SiteNameInput", "SiteName", SiteNameList,selected = NULL, multiple = TRUE),
selectizeInput("LNCELInput", "LNCell", LNCellList,selected = NULL, multiple = TRUE),
selectizeInput("SectorInput", "Sector", SectorList,selected = NULL, multiple = TRUE),
mainPanel(
#plotOutput("distPlot")
verbatimTextOutput("SubRegionText"),
verbatimTextOutput("LCCText"),
verbatimTextOutput("view")
)
)
)
server <- function(input, output) {
observe({
input$SubRegionInput
temp <- SiteInfo[SiteInfo$SITE_SUB_REGION %in% input$SubRegionInput, ]
thisLCCList = sort(temp$BACKHAUL_LCC[!is.na(temp$BACKHAUL_LCC)])
updateSelectizeInput(session = getDefaultReactiveDomain()
, inputId = "LCCInput"
, choices = thisLCCList
, selected= NULL)
thisENBIDList = sort(temp$ENODEB_ID[!is.na(temp$ENODEB_ID)])
updateSelectizeInput(session = getDefaultReactiveDomain()
, inputId = "ENBIDInput"
, choices = thisENBIDList
, selected= NULL)
thisSiteNumberList = sort(temp$SITE_NUMBER[!is.na(temp$SITE_NUMBER)])
updateSelectizeInput(session = getDefaultReactiveDomain()
, inputId = "SiteNumInput"
, choices = thisSiteNumberList
, selected= NULL)
thisSiteNameList = sort(temp$SITE_NAME[!is.na(temp$SITE_NAME)])
updateSelectizeInput(session = getDefaultReactiveDomain()
, inputId = "SiteNameInput"
, choices = thisSiteNameList
, selected= NULL)
thisLNCellList = sort(temp$SECTOR_NUMBER[!is.na(temp$SECTOR_NUMBER)])
updateSelectizeInput(session = getDefaultReactiveDomain()
, inputId = "LNCELInput"
, choices = thisLNCellList
, selected= NULL)
thisSectorList = sort(temp$Sector[!is.na(temp$Sector)])
updateSelectizeInput(session = getDefaultReactiveDomain()
, inputId = "SectorInput"
, choices = thisSectorList
, selected= NULL)
output$view<- renderPrint(temp)
})
【问题讨论】:
标签: r dataframe shiny reactive