我需要帮助确定动态过滤算法
算法应该:
1) Get the input region.csv from user
2) Read list of countries and states from the input table
3) Create a drop-down based on values (c("None", "Country,"State"))
4) Now, when I click None- nothing should come, Country- Only country filter should appear, state-Both country and state.
5) When I click back Country or None, the existing filters of state or country should disappear based on selection.
我能够做前4个步骤。但是当用户点击国家或无人时,我无法清除现有的过滤器。我试过条件面板,但无法做到这一点。有没有简单的方法呢?
编辑:代码和数据
数据:https://docs.google.com/spreadsheets/d/1E9dbtOMm1-7ZjIHu3Ra_NyFBHrCQdITG2_xuMIMKDOs/edit?usp=sharing
ui.r
library(shiny)
shinyUI(fluidPage(
navbarPage(
"DumDum",
tabPanel("Engine",
bootstrapPage(
fileInput("file_attr", "Door attributes:"),
selectInput("select", label = "Level of Normalization", choices = list("None", "Country", "State"), selected = "None"),
uiOutput('output_values')
)
)
)
))
server.r
library(shiny)
shinyServer(function(input, output, session) {
#Reading Input Files
data_attr <- reactive({
file1 <- input$file_attr
if(is.null(file1)){return()}
read.table(file=file1$datapath, sep=",", header = TRUE, stringsAsFactors = FALSE)
})
#Filter interactivity
#Reading Lists
countries <- reactive({
if(is.null(data_attr()$Country)){return()}
data_attr()$Country
})
states <- reactive({
if(is.null(data_attr()$State)){return()}
data_attr()$State
})
#Filters based on Level of normalization
observeEvent(input$file_attr,{
output$output_values <- renderUI({
if (is.null(input$select)){return()}
switch(input$select,
"None" = h3("No normalization selected"),
"Countries" = selectizeInput('show_vars', 'Country Filter', choices = c("Select All","None", unique(countries())), multiple = TRUE),
"States" = selectizeInput('show_vars_state', 'State Filter', choices = c("Select All","None", unique(states())), multiple = TRUE))
})
})
})
当用户点击下拉字段中的“国家/地区”时,过滤器不会显示。此外,如果我们点击国家/地区有没有办法让状态过滤器消失(我的意思是如果我点击国家,只有国家过滤器应该来;状态 - 国家和州过滤器应该出现)
由于
答案 0 :(得分:0)
很难说出你做错了什么,因为我们看不到你的代码。但是如果我理解正确,你想根据selectInput面板的输入生成不同的输出。在这种情况下,我的建议是使用服务器端的uiOutput和redner输出选项。例如:
ui.R
selectInput("filter","Choose a filter",
choices =list("None","Countries","States"), selected = NULL),
uiOutput("output_values")
server.R中的
output$output_values <- renderUI({
if (is.null(input$filter))
return()
switch(input$filter,
"None" = whatever you want to output for none,
"Countries" = whatever you want to output for countries,
"States" = whatever you want to output for states)
})