Issue with Multiple Reactive Filters and Updateselectinputs - Strange BehaviorShiny updateSelectInput for multiple inputsControlling reactivity in ShinyIssue with Shiny and updateSelectInputR selectInput reactivity issuesR shiny selectInput reactivity issuesShiny Reactivity- Multiple elements or One element?Shiny reactivity not working in subModulesR reactive shiny with an updateSelectInputAdd if statement or filter if statement in a reactiveHow to set multiple reactive values and shiny outputs to NULL?

Sprout Reports plugin - How to output a Matrix field into a row

Cyclic queue using an array in C#

Using mean length and mean weight to calculate mean BMI?

My Sixteen Friendly Students

I need some help understanding the grammar of しのげそうな in この寒さをしのげそうな防寒服を手渡され

get unsigned long long addition carry

Do oversize pulley wheels increase derailleur capacity?

Company stopped paying my salary. What are my options?

Is your maximum jump distance halved by grappling?

Where do 5 or more U.S. counties meet in a single point?

What is the oldest instrument ever?

Is it a good idea to copy a trader when investing?

How long can fsck take on a 30 TB volume?

Was Mohammed the most popular first name for boys born in Berlin in 2018?

Whose birthyears are canonically established in the MCU?

Expl3 and recent xparse on overleaf: No expl3 loader detected

Would the rotation of the starfield from a ring station be too disorienting?

Why is it wrong to *implement* myself a known, published, widely believed to be secure crypto algorithm?

Examples where existence is harder than evaluation

Is it safe to keep the GPU on 100% utilization for a very long time?

What should I use to get rid of some kind of weed in my onions

Sed operations are not working or might i am doing it wrong?

Why doesn't increasing the temperature of something like wood or paper set them on fire?

I'm attempting to understand my 401k match and how much I need to contribute to maximize the match



Issue with Multiple Reactive Filters and Updateselectinputs - Strange Behavior


Shiny updateSelectInput for multiple inputsControlling reactivity in ShinyIssue with Shiny and updateSelectInputR selectInput reactivity issuesR shiny selectInput reactivity issuesShiny Reactivity- Multiple elements or One element?Shiny reactivity not working in subModulesR reactive shiny with an updateSelectInputAdd if statement or filter if statement in a reactiveHow to set multiple reactive values and shiny outputs to NULL?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I am struggling to solve an issue with passing multiple filters in a row, and sometimes the result is not as expected. In the example below, there are 7 Deer, 2 Bears, 1 Cougar, 1 Beaver, 1 Skunk, 1 Moose, and 3 Elk. When you select one or more species, sometimes the number of rows passed through the filters is not the same as it should be.



Eg. When I select Bear, Beaver, and Cougar, it should produce data set of 4 rows, however, in the textoutput displaying the number of rows, nrow=3 is displayed. Adding in more selections sometimes passes the remaining filters, sometimes not. Sometimes when selecting Deer, where you would expect 7 rows of data, only 3 are passed.



Have a look at the reproducible example below.



Server:



library(shiny)
library(dplyr)

shinyServer(function(input, output, session, clientData)


Accident.Date <- as.Date(c("2018-06-04", "2018-06-05", "2018-06-06", "2018-06-07", "2018-06-08", "2018-06-09", "2018-06-10", "2018-06-11", "2018-06-12", "2018-06-13", "2018-06-14", "2018-06-15", "2018-06-16", "2018-06-17", "2018-06-18", "2018-07-18"))
Time.of.Kill <- as.character(c("DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DAY", "DAY", "DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DARK", "DUSK", "DARK", "DAY"))
Sex <- as.character(c("MALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "MALE", "MALE", "FEMALE", "FEMALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "FEMALE"))
Age <- as.character(c("ADULT", "YOUNG", "UNKNOWN", "ADULT", "UNKNOWN", "ADULT", "YOUNG", "YOUNG", "ADULT", "ADULT", "ADULT", "YOUNG", "ADULT", "YOUNG", "YOUNG", "ADULT"))
Species <- as.character(c("Deer", "Deer", "Deer", "Bear", "Deer", "Cougar", "Bear", "Beaver", "Deer", "Skunk", "Moose", "Deer", "Deer", "Elk", "Elk", "Elk"))
Year <- as.numeric(c("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"))


data <- data.frame(Accident.Date, Time.of.Kill, Sex, Age, Species, stringsAsFactors = FALSE)
data <- data %>% mutate(Data.Set = "Current")

#A set of reactive filters. Only data that has passed all filters is passed to the map, graph, datatable etc. **Order goes datacheck > yearcheck > speccheck > sexcheck > timecheck > agecheck > indaterange


bindata <- reactive(
filter(data, Data.Set %in% input$datacheck)
)

yrdata <- reactive(
filter(bindata(), Year %in% input$yearcheck)
)

specdata <- reactive(
subset(yrdata(), Species %in% input$speccheck)
)

sexdata <- reactive(
filter(specdata(), Sex %in% input$sexcheck)
)

timedata <- reactive(
filter(sexdata(), Time.of.Kill %in% input$timecheck)
)

agedata <- reactive(
filter(timedata(), Age %in% input$agecheck)
)

#Does the date range filter. Selects min and max from the two inputs of the observed indaterange filter.

data1 <- reactive( filter(agedata(),
Accident.Date >= input$inDateRange[[1]],
Accident.Date <= input$inDateRange[[2]])
)

#If statement for choosing between current and historical datasets. If current is selected, year is set to 0 and the selection box is hidden.

observe( if (input$datacheck == 'Current')
updateSelectInput(session, "yearcheck", choices = c("0"), selected = c("0"))
else
updateSelectizeInput(session, "yearcheck", choices = sort(unique(bindata()$Year), decreasing = TRUE), server=TRUE)

)

observe(

req((input$datacheck == 'Historical'))

updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

)


#Creates the observed Species

observeEvent(input$yearcheck,

x <- input$yearcheck
if (is.null(x))
x <- character(0)

updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

)


#Creates the observed Sex

observeEvent(input$speccheck,

x <- input$speccheck
if (is.null(x))
x <- character(0)

updateCheckboxGroupInput(session, inputId = "sexcheck",
choices = unique(specdata()$Sex),
selected = unique(specdata()$Sex),
inline = TRUE)
)


#Creates the observed Time

observeEvent(input$sexcheck,

x <- input$sexcheck
if (is.null(x))
x <- character(0)

updateCheckboxGroupInput(session, inputId = "timecheck",
choices = unique(sexdata()$Time.of.Kill),
selected = unique(sexdata()$Time.of.Kill),
inline = TRUE)
)

#Creates the observed Age

observeEvent(input$timecheck,

x <- input$timecheck
if (is.null(x))
x <- character(0)

updateCheckboxGroupInput(session, inputId = "agecheck",
choices = unique(timedata()$Age),
selected = unique(timedata()$Age),
inline = TRUE)
)

#Creates the observed dates and suppresses warnings from the min max

observeEvent(input$agecheck,

x <- input$agecheck
if (is.null(x))
x <- character(0)

#And update the date range values to match those of the dataset

updateDateRangeInput(
session = session,
inputId = "inDateRange",
start = min(suppressWarnings(agedata()$Accident.Date)),
end = max(suppressWarnings(agedata()$Accident.Date))
)
)


output$txt <- renderText(nrow(data1()))


)


ui:



navbarPage("Test", id="nav",

tabPanel("Map",

absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
draggable = FALSE, top = 200, left = 5, right = "auto", bottom = "auto",
width = "auto", height = "auto",


radioButtons("datacheck", label = tags$div( HTML("<b>Dataset</b>")),
choices = c("Current" = "Current", "Historical" = "Historical"),
selected = c("Current"), inline = TRUE),



conditionalPanel(condition = "input.datacheck != 'Current'",

#Only displays yearcheck for historical as there is no year column on current dataset. Current dataset has had all year values set to 0.

selectizeInput("yearcheck", label = "Select Year (Only Available for Historical)", choices = NULL, options = list(placeholder = 'Select Year:', maxOptions = 40, maxItems = 40))),

selectizeInput("speccheck", h3("Select Species:"), choices = NULL, options = list(placeholder = 'Select Species: (Max 12) ', maxOptions = 36, maxItems = 12)),


conditionalPanel(condition = "input.speccheck >= '1'",
dateRangeInput("inDateRange", "Date range input:"),

checkboxGroupInput("sexcheck", label = tags$div( HTML("<b>Sex</b><br>"))),

checkboxGroupInput("agecheck", label = tags$div( HTML("<b>Age</b><br>"))),

checkboxGroupInput("timecheck", label = tags$div( HTML("<b>Time of Accident</b><br>")))
),
verbatimTextOutput("txt")


)))


Any help would be appreciated. I have been scratching my head at this one for a while.










share|improve this question




























    1















    I am struggling to solve an issue with passing multiple filters in a row, and sometimes the result is not as expected. In the example below, there are 7 Deer, 2 Bears, 1 Cougar, 1 Beaver, 1 Skunk, 1 Moose, and 3 Elk. When you select one or more species, sometimes the number of rows passed through the filters is not the same as it should be.



    Eg. When I select Bear, Beaver, and Cougar, it should produce data set of 4 rows, however, in the textoutput displaying the number of rows, nrow=3 is displayed. Adding in more selections sometimes passes the remaining filters, sometimes not. Sometimes when selecting Deer, where you would expect 7 rows of data, only 3 are passed.



    Have a look at the reproducible example below.



    Server:



    library(shiny)
    library(dplyr)

    shinyServer(function(input, output, session, clientData)


    Accident.Date <- as.Date(c("2018-06-04", "2018-06-05", "2018-06-06", "2018-06-07", "2018-06-08", "2018-06-09", "2018-06-10", "2018-06-11", "2018-06-12", "2018-06-13", "2018-06-14", "2018-06-15", "2018-06-16", "2018-06-17", "2018-06-18", "2018-07-18"))
    Time.of.Kill <- as.character(c("DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DAY", "DAY", "DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DARK", "DUSK", "DARK", "DAY"))
    Sex <- as.character(c("MALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "MALE", "MALE", "FEMALE", "FEMALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "FEMALE"))
    Age <- as.character(c("ADULT", "YOUNG", "UNKNOWN", "ADULT", "UNKNOWN", "ADULT", "YOUNG", "YOUNG", "ADULT", "ADULT", "ADULT", "YOUNG", "ADULT", "YOUNG", "YOUNG", "ADULT"))
    Species <- as.character(c("Deer", "Deer", "Deer", "Bear", "Deer", "Cougar", "Bear", "Beaver", "Deer", "Skunk", "Moose", "Deer", "Deer", "Elk", "Elk", "Elk"))
    Year <- as.numeric(c("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"))


    data <- data.frame(Accident.Date, Time.of.Kill, Sex, Age, Species, stringsAsFactors = FALSE)
    data <- data %>% mutate(Data.Set = "Current")

    #A set of reactive filters. Only data that has passed all filters is passed to the map, graph, datatable etc. **Order goes datacheck > yearcheck > speccheck > sexcheck > timecheck > agecheck > indaterange


    bindata <- reactive(
    filter(data, Data.Set %in% input$datacheck)
    )

    yrdata <- reactive(
    filter(bindata(), Year %in% input$yearcheck)
    )

    specdata <- reactive(
    subset(yrdata(), Species %in% input$speccheck)
    )

    sexdata <- reactive(
    filter(specdata(), Sex %in% input$sexcheck)
    )

    timedata <- reactive(
    filter(sexdata(), Time.of.Kill %in% input$timecheck)
    )

    agedata <- reactive(
    filter(timedata(), Age %in% input$agecheck)
    )

    #Does the date range filter. Selects min and max from the two inputs of the observed indaterange filter.

    data1 <- reactive( filter(agedata(),
    Accident.Date >= input$inDateRange[[1]],
    Accident.Date <= input$inDateRange[[2]])
    )

    #If statement for choosing between current and historical datasets. If current is selected, year is set to 0 and the selection box is hidden.

    observe( if (input$datacheck == 'Current')
    updateSelectInput(session, "yearcheck", choices = c("0"), selected = c("0"))
    else
    updateSelectizeInput(session, "yearcheck", choices = sort(unique(bindata()$Year), decreasing = TRUE), server=TRUE)

    )

    observe(

    req((input$datacheck == 'Historical'))

    updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

    )


    #Creates the observed Species

    observeEvent(input$yearcheck,

    x <- input$yearcheck
    if (is.null(x))
    x <- character(0)

    updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

    )


    #Creates the observed Sex

    observeEvent(input$speccheck,

    x <- input$speccheck
    if (is.null(x))
    x <- character(0)

    updateCheckboxGroupInput(session, inputId = "sexcheck",
    choices = unique(specdata()$Sex),
    selected = unique(specdata()$Sex),
    inline = TRUE)
    )


    #Creates the observed Time

    observeEvent(input$sexcheck,

    x <- input$sexcheck
    if (is.null(x))
    x <- character(0)

    updateCheckboxGroupInput(session, inputId = "timecheck",
    choices = unique(sexdata()$Time.of.Kill),
    selected = unique(sexdata()$Time.of.Kill),
    inline = TRUE)
    )

    #Creates the observed Age

    observeEvent(input$timecheck,

    x <- input$timecheck
    if (is.null(x))
    x <- character(0)

    updateCheckboxGroupInput(session, inputId = "agecheck",
    choices = unique(timedata()$Age),
    selected = unique(timedata()$Age),
    inline = TRUE)
    )

    #Creates the observed dates and suppresses warnings from the min max

    observeEvent(input$agecheck,

    x <- input$agecheck
    if (is.null(x))
    x <- character(0)

    #And update the date range values to match those of the dataset

    updateDateRangeInput(
    session = session,
    inputId = "inDateRange",
    start = min(suppressWarnings(agedata()$Accident.Date)),
    end = max(suppressWarnings(agedata()$Accident.Date))
    )
    )


    output$txt <- renderText(nrow(data1()))


    )


    ui:



    navbarPage("Test", id="nav",

    tabPanel("Map",

    absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
    draggable = FALSE, top = 200, left = 5, right = "auto", bottom = "auto",
    width = "auto", height = "auto",


    radioButtons("datacheck", label = tags$div( HTML("<b>Dataset</b>")),
    choices = c("Current" = "Current", "Historical" = "Historical"),
    selected = c("Current"), inline = TRUE),



    conditionalPanel(condition = "input.datacheck != 'Current'",

    #Only displays yearcheck for historical as there is no year column on current dataset. Current dataset has had all year values set to 0.

    selectizeInput("yearcheck", label = "Select Year (Only Available for Historical)", choices = NULL, options = list(placeholder = 'Select Year:', maxOptions = 40, maxItems = 40))),

    selectizeInput("speccheck", h3("Select Species:"), choices = NULL, options = list(placeholder = 'Select Species: (Max 12) ', maxOptions = 36, maxItems = 12)),


    conditionalPanel(condition = "input.speccheck >= '1'",
    dateRangeInput("inDateRange", "Date range input:"),

    checkboxGroupInput("sexcheck", label = tags$div( HTML("<b>Sex</b><br>"))),

    checkboxGroupInput("agecheck", label = tags$div( HTML("<b>Age</b><br>"))),

    checkboxGroupInput("timecheck", label = tags$div( HTML("<b>Time of Accident</b><br>")))
    ),
    verbatimTextOutput("txt")


    )))


    Any help would be appreciated. I have been scratching my head at this one for a while.










    share|improve this question
























      1












      1








      1








      I am struggling to solve an issue with passing multiple filters in a row, and sometimes the result is not as expected. In the example below, there are 7 Deer, 2 Bears, 1 Cougar, 1 Beaver, 1 Skunk, 1 Moose, and 3 Elk. When you select one or more species, sometimes the number of rows passed through the filters is not the same as it should be.



      Eg. When I select Bear, Beaver, and Cougar, it should produce data set of 4 rows, however, in the textoutput displaying the number of rows, nrow=3 is displayed. Adding in more selections sometimes passes the remaining filters, sometimes not. Sometimes when selecting Deer, where you would expect 7 rows of data, only 3 are passed.



      Have a look at the reproducible example below.



      Server:



      library(shiny)
      library(dplyr)

      shinyServer(function(input, output, session, clientData)


      Accident.Date <- as.Date(c("2018-06-04", "2018-06-05", "2018-06-06", "2018-06-07", "2018-06-08", "2018-06-09", "2018-06-10", "2018-06-11", "2018-06-12", "2018-06-13", "2018-06-14", "2018-06-15", "2018-06-16", "2018-06-17", "2018-06-18", "2018-07-18"))
      Time.of.Kill <- as.character(c("DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DAY", "DAY", "DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DARK", "DUSK", "DARK", "DAY"))
      Sex <- as.character(c("MALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "MALE", "MALE", "FEMALE", "FEMALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "FEMALE"))
      Age <- as.character(c("ADULT", "YOUNG", "UNKNOWN", "ADULT", "UNKNOWN", "ADULT", "YOUNG", "YOUNG", "ADULT", "ADULT", "ADULT", "YOUNG", "ADULT", "YOUNG", "YOUNG", "ADULT"))
      Species <- as.character(c("Deer", "Deer", "Deer", "Bear", "Deer", "Cougar", "Bear", "Beaver", "Deer", "Skunk", "Moose", "Deer", "Deer", "Elk", "Elk", "Elk"))
      Year <- as.numeric(c("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"))


      data <- data.frame(Accident.Date, Time.of.Kill, Sex, Age, Species, stringsAsFactors = FALSE)
      data <- data %>% mutate(Data.Set = "Current")

      #A set of reactive filters. Only data that has passed all filters is passed to the map, graph, datatable etc. **Order goes datacheck > yearcheck > speccheck > sexcheck > timecheck > agecheck > indaterange


      bindata <- reactive(
      filter(data, Data.Set %in% input$datacheck)
      )

      yrdata <- reactive(
      filter(bindata(), Year %in% input$yearcheck)
      )

      specdata <- reactive(
      subset(yrdata(), Species %in% input$speccheck)
      )

      sexdata <- reactive(
      filter(specdata(), Sex %in% input$sexcheck)
      )

      timedata <- reactive(
      filter(sexdata(), Time.of.Kill %in% input$timecheck)
      )

      agedata <- reactive(
      filter(timedata(), Age %in% input$agecheck)
      )

      #Does the date range filter. Selects min and max from the two inputs of the observed indaterange filter.

      data1 <- reactive( filter(agedata(),
      Accident.Date >= input$inDateRange[[1]],
      Accident.Date <= input$inDateRange[[2]])
      )

      #If statement for choosing between current and historical datasets. If current is selected, year is set to 0 and the selection box is hidden.

      observe( if (input$datacheck == 'Current')
      updateSelectInput(session, "yearcheck", choices = c("0"), selected = c("0"))
      else
      updateSelectizeInput(session, "yearcheck", choices = sort(unique(bindata()$Year), decreasing = TRUE), server=TRUE)

      )

      observe(

      req((input$datacheck == 'Historical'))

      updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

      )


      #Creates the observed Species

      observeEvent(input$yearcheck,

      x <- input$yearcheck
      if (is.null(x))
      x <- character(0)

      updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

      )


      #Creates the observed Sex

      observeEvent(input$speccheck,

      x <- input$speccheck
      if (is.null(x))
      x <- character(0)

      updateCheckboxGroupInput(session, inputId = "sexcheck",
      choices = unique(specdata()$Sex),
      selected = unique(specdata()$Sex),
      inline = TRUE)
      )


      #Creates the observed Time

      observeEvent(input$sexcheck,

      x <- input$sexcheck
      if (is.null(x))
      x <- character(0)

      updateCheckboxGroupInput(session, inputId = "timecheck",
      choices = unique(sexdata()$Time.of.Kill),
      selected = unique(sexdata()$Time.of.Kill),
      inline = TRUE)
      )

      #Creates the observed Age

      observeEvent(input$timecheck,

      x <- input$timecheck
      if (is.null(x))
      x <- character(0)

      updateCheckboxGroupInput(session, inputId = "agecheck",
      choices = unique(timedata()$Age),
      selected = unique(timedata()$Age),
      inline = TRUE)
      )

      #Creates the observed dates and suppresses warnings from the min max

      observeEvent(input$agecheck,

      x <- input$agecheck
      if (is.null(x))
      x <- character(0)

      #And update the date range values to match those of the dataset

      updateDateRangeInput(
      session = session,
      inputId = "inDateRange",
      start = min(suppressWarnings(agedata()$Accident.Date)),
      end = max(suppressWarnings(agedata()$Accident.Date))
      )
      )


      output$txt <- renderText(nrow(data1()))


      )


      ui:



      navbarPage("Test", id="nav",

      tabPanel("Map",

      absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
      draggable = FALSE, top = 200, left = 5, right = "auto", bottom = "auto",
      width = "auto", height = "auto",


      radioButtons("datacheck", label = tags$div( HTML("<b>Dataset</b>")),
      choices = c("Current" = "Current", "Historical" = "Historical"),
      selected = c("Current"), inline = TRUE),



      conditionalPanel(condition = "input.datacheck != 'Current'",

      #Only displays yearcheck for historical as there is no year column on current dataset. Current dataset has had all year values set to 0.

      selectizeInput("yearcheck", label = "Select Year (Only Available for Historical)", choices = NULL, options = list(placeholder = 'Select Year:', maxOptions = 40, maxItems = 40))),

      selectizeInput("speccheck", h3("Select Species:"), choices = NULL, options = list(placeholder = 'Select Species: (Max 12) ', maxOptions = 36, maxItems = 12)),


      conditionalPanel(condition = "input.speccheck >= '1'",
      dateRangeInput("inDateRange", "Date range input:"),

      checkboxGroupInput("sexcheck", label = tags$div( HTML("<b>Sex</b><br>"))),

      checkboxGroupInput("agecheck", label = tags$div( HTML("<b>Age</b><br>"))),

      checkboxGroupInput("timecheck", label = tags$div( HTML("<b>Time of Accident</b><br>")))
      ),
      verbatimTextOutput("txt")


      )))


      Any help would be appreciated. I have been scratching my head at this one for a while.










      share|improve this question














      I am struggling to solve an issue with passing multiple filters in a row, and sometimes the result is not as expected. In the example below, there are 7 Deer, 2 Bears, 1 Cougar, 1 Beaver, 1 Skunk, 1 Moose, and 3 Elk. When you select one or more species, sometimes the number of rows passed through the filters is not the same as it should be.



      Eg. When I select Bear, Beaver, and Cougar, it should produce data set of 4 rows, however, in the textoutput displaying the number of rows, nrow=3 is displayed. Adding in more selections sometimes passes the remaining filters, sometimes not. Sometimes when selecting Deer, where you would expect 7 rows of data, only 3 are passed.



      Have a look at the reproducible example below.



      Server:



      library(shiny)
      library(dplyr)

      shinyServer(function(input, output, session, clientData)


      Accident.Date <- as.Date(c("2018-06-04", "2018-06-05", "2018-06-06", "2018-06-07", "2018-06-08", "2018-06-09", "2018-06-10", "2018-06-11", "2018-06-12", "2018-06-13", "2018-06-14", "2018-06-15", "2018-06-16", "2018-06-17", "2018-06-18", "2018-07-18"))
      Time.of.Kill <- as.character(c("DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DAY", "DAY", "DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DARK", "DUSK", "DARK", "DAY"))
      Sex <- as.character(c("MALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "MALE", "MALE", "FEMALE", "FEMALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "FEMALE"))
      Age <- as.character(c("ADULT", "YOUNG", "UNKNOWN", "ADULT", "UNKNOWN", "ADULT", "YOUNG", "YOUNG", "ADULT", "ADULT", "ADULT", "YOUNG", "ADULT", "YOUNG", "YOUNG", "ADULT"))
      Species <- as.character(c("Deer", "Deer", "Deer", "Bear", "Deer", "Cougar", "Bear", "Beaver", "Deer", "Skunk", "Moose", "Deer", "Deer", "Elk", "Elk", "Elk"))
      Year <- as.numeric(c("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"))


      data <- data.frame(Accident.Date, Time.of.Kill, Sex, Age, Species, stringsAsFactors = FALSE)
      data <- data %>% mutate(Data.Set = "Current")

      #A set of reactive filters. Only data that has passed all filters is passed to the map, graph, datatable etc. **Order goes datacheck > yearcheck > speccheck > sexcheck > timecheck > agecheck > indaterange


      bindata <- reactive(
      filter(data, Data.Set %in% input$datacheck)
      )

      yrdata <- reactive(
      filter(bindata(), Year %in% input$yearcheck)
      )

      specdata <- reactive(
      subset(yrdata(), Species %in% input$speccheck)
      )

      sexdata <- reactive(
      filter(specdata(), Sex %in% input$sexcheck)
      )

      timedata <- reactive(
      filter(sexdata(), Time.of.Kill %in% input$timecheck)
      )

      agedata <- reactive(
      filter(timedata(), Age %in% input$agecheck)
      )

      #Does the date range filter. Selects min and max from the two inputs of the observed indaterange filter.

      data1 <- reactive( filter(agedata(),
      Accident.Date >= input$inDateRange[[1]],
      Accident.Date <= input$inDateRange[[2]])
      )

      #If statement for choosing between current and historical datasets. If current is selected, year is set to 0 and the selection box is hidden.

      observe( if (input$datacheck == 'Current')
      updateSelectInput(session, "yearcheck", choices = c("0"), selected = c("0"))
      else
      updateSelectizeInput(session, "yearcheck", choices = sort(unique(bindata()$Year), decreasing = TRUE), server=TRUE)

      )

      observe(

      req((input$datacheck == 'Historical'))

      updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

      )


      #Creates the observed Species

      observeEvent(input$yearcheck,

      x <- input$yearcheck
      if (is.null(x))
      x <- character(0)

      updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

      )


      #Creates the observed Sex

      observeEvent(input$speccheck,

      x <- input$speccheck
      if (is.null(x))
      x <- character(0)

      updateCheckboxGroupInput(session, inputId = "sexcheck",
      choices = unique(specdata()$Sex),
      selected = unique(specdata()$Sex),
      inline = TRUE)
      )


      #Creates the observed Time

      observeEvent(input$sexcheck,

      x <- input$sexcheck
      if (is.null(x))
      x <- character(0)

      updateCheckboxGroupInput(session, inputId = "timecheck",
      choices = unique(sexdata()$Time.of.Kill),
      selected = unique(sexdata()$Time.of.Kill),
      inline = TRUE)
      )

      #Creates the observed Age

      observeEvent(input$timecheck,

      x <- input$timecheck
      if (is.null(x))
      x <- character(0)

      updateCheckboxGroupInput(session, inputId = "agecheck",
      choices = unique(timedata()$Age),
      selected = unique(timedata()$Age),
      inline = TRUE)
      )

      #Creates the observed dates and suppresses warnings from the min max

      observeEvent(input$agecheck,

      x <- input$agecheck
      if (is.null(x))
      x <- character(0)

      #And update the date range values to match those of the dataset

      updateDateRangeInput(
      session = session,
      inputId = "inDateRange",
      start = min(suppressWarnings(agedata()$Accident.Date)),
      end = max(suppressWarnings(agedata()$Accident.Date))
      )
      )


      output$txt <- renderText(nrow(data1()))


      )


      ui:



      navbarPage("Test", id="nav",

      tabPanel("Map",

      absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
      draggable = FALSE, top = 200, left = 5, right = "auto", bottom = "auto",
      width = "auto", height = "auto",


      radioButtons("datacheck", label = tags$div( HTML("<b>Dataset</b>")),
      choices = c("Current" = "Current", "Historical" = "Historical"),
      selected = c("Current"), inline = TRUE),



      conditionalPanel(condition = "input.datacheck != 'Current'",

      #Only displays yearcheck for historical as there is no year column on current dataset. Current dataset has had all year values set to 0.

      selectizeInput("yearcheck", label = "Select Year (Only Available for Historical)", choices = NULL, options = list(placeholder = 'Select Year:', maxOptions = 40, maxItems = 40))),

      selectizeInput("speccheck", h3("Select Species:"), choices = NULL, options = list(placeholder = 'Select Species: (Max 12) ', maxOptions = 36, maxItems = 12)),


      conditionalPanel(condition = "input.speccheck >= '1'",
      dateRangeInput("inDateRange", "Date range input:"),

      checkboxGroupInput("sexcheck", label = tags$div( HTML("<b>Sex</b><br>"))),

      checkboxGroupInput("agecheck", label = tags$div( HTML("<b>Age</b><br>"))),

      checkboxGroupInput("timecheck", label = tags$div( HTML("<b>Time of Accident</b><br>")))
      ),
      verbatimTextOutput("txt")


      )))


      Any help would be appreciated. I have been scratching my head at this one for a while.







      r shiny shiny-reactivity






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 22 at 23:33









      Jayman McAllisterJayman McAllister

      134




      134






















          2 Answers
          2






          active

          oldest

          votes


















          0














          The issue is related with how you update your checkbox. Using your code: select first BEAR, the output looks great, yeah, but if you add BEAVER nothing happens. Why? Because when your filter pass



           timedata <- reactive(
          filter(sexdata(),(Time.of.Kill %in% input$timecheck))
          )


          Because BEAR has not DAWN as a Time.of.Kill, BEAVER does not pass this filter.



          Here is my solution:



          shinyServer(function(input, output, session, clientData) 


          Accident.Date <- as.Date(c("2018-06-04", "2018-06-05", "2018-06-06", "2018-06-07", "2018-06-08", "2018-06-09", "2018-06-10", "2018-06-11", "2018-06-12", "2018-06-13", "2018-06-14", "2018-06-15", "2018-06-16", "2018-06-17", "2018-06-18", "2018-07-18"))
          Time.of.Kill <- as.character(c("DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DAY", "DAY", "DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DARK", "DUSK", "DARK", "DAY"))
          Sex <- as.character(c("MALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "MALE", "MALE", "FEMALE", "FEMALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "FEMALE"))
          Age <- as.character(c("ADULT", "YOUNG", "UNKNOWN", "ADULT", "UNKNOWN", "ADULT", "YOUNG", "YOUNG", "ADULT", "ADULT", "ADULT", "YOUNG", "ADULT", "YOUNG", "YOUNG", "ADULT"))
          Species <- as.character(c("Deer", "Deer", "Deer", "Bear", "Deer", "Cougar", "Bear", "Beaver", "Deer", "Skunk", "Moose", "Deer", "Deer", "Elk", "Elk", "Elk"))
          Year <- as.numeric(c("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"))


          data <- data.frame(Accident.Date, Time.of.Kill, Sex, Age, Species, stringsAsFactors = FALSE)
          data <- data %>% mutate(Data.Set = "Current")

          #A set of reactive filters. Only data that has passed all filters is passed to the map, graph, datatable etc. **Order goes datacheck > yearcheck > speccheck > sexcheck > timecheck > agecheck > indaterange


          bindata <- reactive(
          filter(data, Data.Set %in% input$datacheck)
          )

          yrdata <- reactive(
          filter(bindata(), Year %in% input$yearcheck)
          )

          specdata <- reactive(
          sub <- subset(yrdata(), Species %in% input$speccheck)

          )

          sexdata <- reactive(
          filter(specdata(), Sex %in% input$sexcheck)
          )

          timedata <- reactive(
          filter(sexdata(),(Time.of.Kill %in% input$timecheck))
          )

          agedata <- reactive(
          filter(timedata(), Age %in% input$agecheck)
          )

          #Does the date range filter. Selects min and max from the two inputs of the observed indaterange filter.

          data1 <- reactive( filter(agedata(),
          Accident.Date >= input$inDateRange[[1]],
          Accident.Date <= input$inDateRange[[2]])
          )

          #If statement for choosing between current and historical datasets. If current is selected, year is set to 0 and the selection box is hidden.

          observe( if (input$datacheck == 'Current')
          updateSelectInput(session, "yearcheck", choices = c("0"), selected = c("0"))
          else
          updateSelectizeInput(session, "yearcheck", choices = sort(unique(bindata()$Year), decreasing = TRUE), server=TRUE)

          )

          observe(

          req((input$datacheck == 'Historical'))

          updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

          )


          #Creates the observed Species

          observeEvent(input$yearcheck,

          x <- input$yearcheck
          if (is.null(x))
          x <- character(0)

          updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

          )


          #Creates the observed Sex

          observeEvent(input$speccheck,

          x <- input$speccheck
          if (is.null(x))
          x <- character(0)

          updateCheckboxGroupInput(session, inputId = "sexcheck",
          choices = unique(bindata()$Sex),
          selected = unique(bindata()$Sex),
          inline = TRUE)
          )


          #Creates the observed Time

          observeEvent(input$sexcheck,

          x <- input$sexcheck
          if (is.null(x))
          x <- character(0)

          updateCheckboxGroupInput(session, inputId = "timecheck",
          choices = unique(bindata()$Time.of.Kill),
          selected = unique(bindata()$Time.of.Kill),
          inline = TRUE)
          )

          #Creates the observed Age

          observeEvent(input$timecheck,

          x <- input$timecheck
          if (is.null(x))
          x <- character(0)

          updateCheckboxGroupInput(session, inputId = "agecheck",
          choices = unique(bindata()$Age),
          selected = unique(bindata()$Age),
          inline = TRUE)
          )

          #Creates the observed dates and suppresses warnings from the min max

          observeEvent(input$agecheck,

          x <- input$agecheck
          if (is.null(x))
          x <- character(0)

          #And update the date range values to match those of the dataset

          updateDateRangeInput(
          session = session,
          inputId = "inDateRange",
          start = min(suppressWarnings(bindata()$Accident.Date)),
          end = max(suppressWarnings(bindata()$Accident.Date))
          )
          )


          output$txt <- renderText(nrow(data1()))


          )


          My only change is to use bindata() to update checkboxs, this will force all to appear so no animal is pre-filtered.
          Therefore, my solution is to renounce to create dynamic checks and show all from the very first time you select an animal.






          share|improve this answer























          • Close but I solved it. Thanks for the advice.

            – Jayman McAllister
            Mar 24 at 0:50


















          0














          The solution was rather obvious. The desired effect was obtained by just placing the updateinputs inside of observe() rather than trying to observe the upstream inputs as they change. This was applied to all upstream updateinputs.



           observe(

          x <- input$agecheck
          if (is.null(x))
          x <- character(0)

          #And update the date range values to match those of the dataset

          updateDateRangeInput(
          session = session,
          inputId = "inDateRange",
          start = suppressWarnings(min(agedata()$Accident.Date)),
          end = suppressWarnings(max(agedata()$Accident.Date))
          )
          )


          This solved the problem!






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309078%2fissue-with-multiple-reactive-filters-and-updateselectinputs-strange-behavior%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The issue is related with how you update your checkbox. Using your code: select first BEAR, the output looks great, yeah, but if you add BEAVER nothing happens. Why? Because when your filter pass



             timedata <- reactive(
            filter(sexdata(),(Time.of.Kill %in% input$timecheck))
            )


            Because BEAR has not DAWN as a Time.of.Kill, BEAVER does not pass this filter.



            Here is my solution:



            shinyServer(function(input, output, session, clientData) 


            Accident.Date <- as.Date(c("2018-06-04", "2018-06-05", "2018-06-06", "2018-06-07", "2018-06-08", "2018-06-09", "2018-06-10", "2018-06-11", "2018-06-12", "2018-06-13", "2018-06-14", "2018-06-15", "2018-06-16", "2018-06-17", "2018-06-18", "2018-07-18"))
            Time.of.Kill <- as.character(c("DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DAY", "DAY", "DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DARK", "DUSK", "DARK", "DAY"))
            Sex <- as.character(c("MALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "MALE", "MALE", "FEMALE", "FEMALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "FEMALE"))
            Age <- as.character(c("ADULT", "YOUNG", "UNKNOWN", "ADULT", "UNKNOWN", "ADULT", "YOUNG", "YOUNG", "ADULT", "ADULT", "ADULT", "YOUNG", "ADULT", "YOUNG", "YOUNG", "ADULT"))
            Species <- as.character(c("Deer", "Deer", "Deer", "Bear", "Deer", "Cougar", "Bear", "Beaver", "Deer", "Skunk", "Moose", "Deer", "Deer", "Elk", "Elk", "Elk"))
            Year <- as.numeric(c("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"))


            data <- data.frame(Accident.Date, Time.of.Kill, Sex, Age, Species, stringsAsFactors = FALSE)
            data <- data %>% mutate(Data.Set = "Current")

            #A set of reactive filters. Only data that has passed all filters is passed to the map, graph, datatable etc. **Order goes datacheck > yearcheck > speccheck > sexcheck > timecheck > agecheck > indaterange


            bindata <- reactive(
            filter(data, Data.Set %in% input$datacheck)
            )

            yrdata <- reactive(
            filter(bindata(), Year %in% input$yearcheck)
            )

            specdata <- reactive(
            sub <- subset(yrdata(), Species %in% input$speccheck)

            )

            sexdata <- reactive(
            filter(specdata(), Sex %in% input$sexcheck)
            )

            timedata <- reactive(
            filter(sexdata(),(Time.of.Kill %in% input$timecheck))
            )

            agedata <- reactive(
            filter(timedata(), Age %in% input$agecheck)
            )

            #Does the date range filter. Selects min and max from the two inputs of the observed indaterange filter.

            data1 <- reactive( filter(agedata(),
            Accident.Date >= input$inDateRange[[1]],
            Accident.Date <= input$inDateRange[[2]])
            )

            #If statement for choosing between current and historical datasets. If current is selected, year is set to 0 and the selection box is hidden.

            observe( if (input$datacheck == 'Current')
            updateSelectInput(session, "yearcheck", choices = c("0"), selected = c("0"))
            else
            updateSelectizeInput(session, "yearcheck", choices = sort(unique(bindata()$Year), decreasing = TRUE), server=TRUE)

            )

            observe(

            req((input$datacheck == 'Historical'))

            updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

            )


            #Creates the observed Species

            observeEvent(input$yearcheck,

            x <- input$yearcheck
            if (is.null(x))
            x <- character(0)

            updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

            )


            #Creates the observed Sex

            observeEvent(input$speccheck,

            x <- input$speccheck
            if (is.null(x))
            x <- character(0)

            updateCheckboxGroupInput(session, inputId = "sexcheck",
            choices = unique(bindata()$Sex),
            selected = unique(bindata()$Sex),
            inline = TRUE)
            )


            #Creates the observed Time

            observeEvent(input$sexcheck,

            x <- input$sexcheck
            if (is.null(x))
            x <- character(0)

            updateCheckboxGroupInput(session, inputId = "timecheck",
            choices = unique(bindata()$Time.of.Kill),
            selected = unique(bindata()$Time.of.Kill),
            inline = TRUE)
            )

            #Creates the observed Age

            observeEvent(input$timecheck,

            x <- input$timecheck
            if (is.null(x))
            x <- character(0)

            updateCheckboxGroupInput(session, inputId = "agecheck",
            choices = unique(bindata()$Age),
            selected = unique(bindata()$Age),
            inline = TRUE)
            )

            #Creates the observed dates and suppresses warnings from the min max

            observeEvent(input$agecheck,

            x <- input$agecheck
            if (is.null(x))
            x <- character(0)

            #And update the date range values to match those of the dataset

            updateDateRangeInput(
            session = session,
            inputId = "inDateRange",
            start = min(suppressWarnings(bindata()$Accident.Date)),
            end = max(suppressWarnings(bindata()$Accident.Date))
            )
            )


            output$txt <- renderText(nrow(data1()))


            )


            My only change is to use bindata() to update checkboxs, this will force all to appear so no animal is pre-filtered.
            Therefore, my solution is to renounce to create dynamic checks and show all from the very first time you select an animal.






            share|improve this answer























            • Close but I solved it. Thanks for the advice.

              – Jayman McAllister
              Mar 24 at 0:50















            0














            The issue is related with how you update your checkbox. Using your code: select first BEAR, the output looks great, yeah, but if you add BEAVER nothing happens. Why? Because when your filter pass



             timedata <- reactive(
            filter(sexdata(),(Time.of.Kill %in% input$timecheck))
            )


            Because BEAR has not DAWN as a Time.of.Kill, BEAVER does not pass this filter.



            Here is my solution:



            shinyServer(function(input, output, session, clientData) 


            Accident.Date <- as.Date(c("2018-06-04", "2018-06-05", "2018-06-06", "2018-06-07", "2018-06-08", "2018-06-09", "2018-06-10", "2018-06-11", "2018-06-12", "2018-06-13", "2018-06-14", "2018-06-15", "2018-06-16", "2018-06-17", "2018-06-18", "2018-07-18"))
            Time.of.Kill <- as.character(c("DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DAY", "DAY", "DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DARK", "DUSK", "DARK", "DAY"))
            Sex <- as.character(c("MALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "MALE", "MALE", "FEMALE", "FEMALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "FEMALE"))
            Age <- as.character(c("ADULT", "YOUNG", "UNKNOWN", "ADULT", "UNKNOWN", "ADULT", "YOUNG", "YOUNG", "ADULT", "ADULT", "ADULT", "YOUNG", "ADULT", "YOUNG", "YOUNG", "ADULT"))
            Species <- as.character(c("Deer", "Deer", "Deer", "Bear", "Deer", "Cougar", "Bear", "Beaver", "Deer", "Skunk", "Moose", "Deer", "Deer", "Elk", "Elk", "Elk"))
            Year <- as.numeric(c("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"))


            data <- data.frame(Accident.Date, Time.of.Kill, Sex, Age, Species, stringsAsFactors = FALSE)
            data <- data %>% mutate(Data.Set = "Current")

            #A set of reactive filters. Only data that has passed all filters is passed to the map, graph, datatable etc. **Order goes datacheck > yearcheck > speccheck > sexcheck > timecheck > agecheck > indaterange


            bindata <- reactive(
            filter(data, Data.Set %in% input$datacheck)
            )

            yrdata <- reactive(
            filter(bindata(), Year %in% input$yearcheck)
            )

            specdata <- reactive(
            sub <- subset(yrdata(), Species %in% input$speccheck)

            )

            sexdata <- reactive(
            filter(specdata(), Sex %in% input$sexcheck)
            )

            timedata <- reactive(
            filter(sexdata(),(Time.of.Kill %in% input$timecheck))
            )

            agedata <- reactive(
            filter(timedata(), Age %in% input$agecheck)
            )

            #Does the date range filter. Selects min and max from the two inputs of the observed indaterange filter.

            data1 <- reactive( filter(agedata(),
            Accident.Date >= input$inDateRange[[1]],
            Accident.Date <= input$inDateRange[[2]])
            )

            #If statement for choosing between current and historical datasets. If current is selected, year is set to 0 and the selection box is hidden.

            observe( if (input$datacheck == 'Current')
            updateSelectInput(session, "yearcheck", choices = c("0"), selected = c("0"))
            else
            updateSelectizeInput(session, "yearcheck", choices = sort(unique(bindata()$Year), decreasing = TRUE), server=TRUE)

            )

            observe(

            req((input$datacheck == 'Historical'))

            updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

            )


            #Creates the observed Species

            observeEvent(input$yearcheck,

            x <- input$yearcheck
            if (is.null(x))
            x <- character(0)

            updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

            )


            #Creates the observed Sex

            observeEvent(input$speccheck,

            x <- input$speccheck
            if (is.null(x))
            x <- character(0)

            updateCheckboxGroupInput(session, inputId = "sexcheck",
            choices = unique(bindata()$Sex),
            selected = unique(bindata()$Sex),
            inline = TRUE)
            )


            #Creates the observed Time

            observeEvent(input$sexcheck,

            x <- input$sexcheck
            if (is.null(x))
            x <- character(0)

            updateCheckboxGroupInput(session, inputId = "timecheck",
            choices = unique(bindata()$Time.of.Kill),
            selected = unique(bindata()$Time.of.Kill),
            inline = TRUE)
            )

            #Creates the observed Age

            observeEvent(input$timecheck,

            x <- input$timecheck
            if (is.null(x))
            x <- character(0)

            updateCheckboxGroupInput(session, inputId = "agecheck",
            choices = unique(bindata()$Age),
            selected = unique(bindata()$Age),
            inline = TRUE)
            )

            #Creates the observed dates and suppresses warnings from the min max

            observeEvent(input$agecheck,

            x <- input$agecheck
            if (is.null(x))
            x <- character(0)

            #And update the date range values to match those of the dataset

            updateDateRangeInput(
            session = session,
            inputId = "inDateRange",
            start = min(suppressWarnings(bindata()$Accident.Date)),
            end = max(suppressWarnings(bindata()$Accident.Date))
            )
            )


            output$txt <- renderText(nrow(data1()))


            )


            My only change is to use bindata() to update checkboxs, this will force all to appear so no animal is pre-filtered.
            Therefore, my solution is to renounce to create dynamic checks and show all from the very first time you select an animal.






            share|improve this answer























            • Close but I solved it. Thanks for the advice.

              – Jayman McAllister
              Mar 24 at 0:50













            0












            0








            0







            The issue is related with how you update your checkbox. Using your code: select first BEAR, the output looks great, yeah, but if you add BEAVER nothing happens. Why? Because when your filter pass



             timedata <- reactive(
            filter(sexdata(),(Time.of.Kill %in% input$timecheck))
            )


            Because BEAR has not DAWN as a Time.of.Kill, BEAVER does not pass this filter.



            Here is my solution:



            shinyServer(function(input, output, session, clientData) 


            Accident.Date <- as.Date(c("2018-06-04", "2018-06-05", "2018-06-06", "2018-06-07", "2018-06-08", "2018-06-09", "2018-06-10", "2018-06-11", "2018-06-12", "2018-06-13", "2018-06-14", "2018-06-15", "2018-06-16", "2018-06-17", "2018-06-18", "2018-07-18"))
            Time.of.Kill <- as.character(c("DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DAY", "DAY", "DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DARK", "DUSK", "DARK", "DAY"))
            Sex <- as.character(c("MALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "MALE", "MALE", "FEMALE", "FEMALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "FEMALE"))
            Age <- as.character(c("ADULT", "YOUNG", "UNKNOWN", "ADULT", "UNKNOWN", "ADULT", "YOUNG", "YOUNG", "ADULT", "ADULT", "ADULT", "YOUNG", "ADULT", "YOUNG", "YOUNG", "ADULT"))
            Species <- as.character(c("Deer", "Deer", "Deer", "Bear", "Deer", "Cougar", "Bear", "Beaver", "Deer", "Skunk", "Moose", "Deer", "Deer", "Elk", "Elk", "Elk"))
            Year <- as.numeric(c("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"))


            data <- data.frame(Accident.Date, Time.of.Kill, Sex, Age, Species, stringsAsFactors = FALSE)
            data <- data %>% mutate(Data.Set = "Current")

            #A set of reactive filters. Only data that has passed all filters is passed to the map, graph, datatable etc. **Order goes datacheck > yearcheck > speccheck > sexcheck > timecheck > agecheck > indaterange


            bindata <- reactive(
            filter(data, Data.Set %in% input$datacheck)
            )

            yrdata <- reactive(
            filter(bindata(), Year %in% input$yearcheck)
            )

            specdata <- reactive(
            sub <- subset(yrdata(), Species %in% input$speccheck)

            )

            sexdata <- reactive(
            filter(specdata(), Sex %in% input$sexcheck)
            )

            timedata <- reactive(
            filter(sexdata(),(Time.of.Kill %in% input$timecheck))
            )

            agedata <- reactive(
            filter(timedata(), Age %in% input$agecheck)
            )

            #Does the date range filter. Selects min and max from the two inputs of the observed indaterange filter.

            data1 <- reactive( filter(agedata(),
            Accident.Date >= input$inDateRange[[1]],
            Accident.Date <= input$inDateRange[[2]])
            )

            #If statement for choosing between current and historical datasets. If current is selected, year is set to 0 and the selection box is hidden.

            observe( if (input$datacheck == 'Current')
            updateSelectInput(session, "yearcheck", choices = c("0"), selected = c("0"))
            else
            updateSelectizeInput(session, "yearcheck", choices = sort(unique(bindata()$Year), decreasing = TRUE), server=TRUE)

            )

            observe(

            req((input$datacheck == 'Historical'))

            updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

            )


            #Creates the observed Species

            observeEvent(input$yearcheck,

            x <- input$yearcheck
            if (is.null(x))
            x <- character(0)

            updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

            )


            #Creates the observed Sex

            observeEvent(input$speccheck,

            x <- input$speccheck
            if (is.null(x))
            x <- character(0)

            updateCheckboxGroupInput(session, inputId = "sexcheck",
            choices = unique(bindata()$Sex),
            selected = unique(bindata()$Sex),
            inline = TRUE)
            )


            #Creates the observed Time

            observeEvent(input$sexcheck,

            x <- input$sexcheck
            if (is.null(x))
            x <- character(0)

            updateCheckboxGroupInput(session, inputId = "timecheck",
            choices = unique(bindata()$Time.of.Kill),
            selected = unique(bindata()$Time.of.Kill),
            inline = TRUE)
            )

            #Creates the observed Age

            observeEvent(input$timecheck,

            x <- input$timecheck
            if (is.null(x))
            x <- character(0)

            updateCheckboxGroupInput(session, inputId = "agecheck",
            choices = unique(bindata()$Age),
            selected = unique(bindata()$Age),
            inline = TRUE)
            )

            #Creates the observed dates and suppresses warnings from the min max

            observeEvent(input$agecheck,

            x <- input$agecheck
            if (is.null(x))
            x <- character(0)

            #And update the date range values to match those of the dataset

            updateDateRangeInput(
            session = session,
            inputId = "inDateRange",
            start = min(suppressWarnings(bindata()$Accident.Date)),
            end = max(suppressWarnings(bindata()$Accident.Date))
            )
            )


            output$txt <- renderText(nrow(data1()))


            )


            My only change is to use bindata() to update checkboxs, this will force all to appear so no animal is pre-filtered.
            Therefore, my solution is to renounce to create dynamic checks and show all from the very first time you select an animal.






            share|improve this answer













            The issue is related with how you update your checkbox. Using your code: select first BEAR, the output looks great, yeah, but if you add BEAVER nothing happens. Why? Because when your filter pass



             timedata <- reactive(
            filter(sexdata(),(Time.of.Kill %in% input$timecheck))
            )


            Because BEAR has not DAWN as a Time.of.Kill, BEAVER does not pass this filter.



            Here is my solution:



            shinyServer(function(input, output, session, clientData) 


            Accident.Date <- as.Date(c("2018-06-04", "2018-06-05", "2018-06-06", "2018-06-07", "2018-06-08", "2018-06-09", "2018-06-10", "2018-06-11", "2018-06-12", "2018-06-13", "2018-06-14", "2018-06-15", "2018-06-16", "2018-06-17", "2018-06-18", "2018-07-18"))
            Time.of.Kill <- as.character(c("DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DAY", "DAY", "DAWN", "DAY", "DARK", "UNKNOWN", "DUSK", "DARK", "DUSK", "DARK", "DAY"))
            Sex <- as.character(c("MALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "MALE", "MALE", "FEMALE", "FEMALE", "MALE", "FEMALE", "MALE", "FEMALE", "FEMALE", "FEMALE"))
            Age <- as.character(c("ADULT", "YOUNG", "UNKNOWN", "ADULT", "UNKNOWN", "ADULT", "YOUNG", "YOUNG", "ADULT", "ADULT", "ADULT", "YOUNG", "ADULT", "YOUNG", "YOUNG", "ADULT"))
            Species <- as.character(c("Deer", "Deer", "Deer", "Bear", "Deer", "Cougar", "Bear", "Beaver", "Deer", "Skunk", "Moose", "Deer", "Deer", "Elk", "Elk", "Elk"))
            Year <- as.numeric(c("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"))


            data <- data.frame(Accident.Date, Time.of.Kill, Sex, Age, Species, stringsAsFactors = FALSE)
            data <- data %>% mutate(Data.Set = "Current")

            #A set of reactive filters. Only data that has passed all filters is passed to the map, graph, datatable etc. **Order goes datacheck > yearcheck > speccheck > sexcheck > timecheck > agecheck > indaterange


            bindata <- reactive(
            filter(data, Data.Set %in% input$datacheck)
            )

            yrdata <- reactive(
            filter(bindata(), Year %in% input$yearcheck)
            )

            specdata <- reactive(
            sub <- subset(yrdata(), Species %in% input$speccheck)

            )

            sexdata <- reactive(
            filter(specdata(), Sex %in% input$sexcheck)
            )

            timedata <- reactive(
            filter(sexdata(),(Time.of.Kill %in% input$timecheck))
            )

            agedata <- reactive(
            filter(timedata(), Age %in% input$agecheck)
            )

            #Does the date range filter. Selects min and max from the two inputs of the observed indaterange filter.

            data1 <- reactive( filter(agedata(),
            Accident.Date >= input$inDateRange[[1]],
            Accident.Date <= input$inDateRange[[2]])
            )

            #If statement for choosing between current and historical datasets. If current is selected, year is set to 0 and the selection box is hidden.

            observe( if (input$datacheck == 'Current')
            updateSelectInput(session, "yearcheck", choices = c("0"), selected = c("0"))
            else
            updateSelectizeInput(session, "yearcheck", choices = sort(unique(bindata()$Year), decreasing = TRUE), server=TRUE)

            )

            observe(

            req((input$datacheck == 'Historical'))

            updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

            )


            #Creates the observed Species

            observeEvent(input$yearcheck,

            x <- input$yearcheck
            if (is.null(x))
            x <- character(0)

            updateSelectizeInput(session, "speccheck", choices = sort(unique(yrdata()$Species)), server=TRUE)

            )


            #Creates the observed Sex

            observeEvent(input$speccheck,

            x <- input$speccheck
            if (is.null(x))
            x <- character(0)

            updateCheckboxGroupInput(session, inputId = "sexcheck",
            choices = unique(bindata()$Sex),
            selected = unique(bindata()$Sex),
            inline = TRUE)
            )


            #Creates the observed Time

            observeEvent(input$sexcheck,

            x <- input$sexcheck
            if (is.null(x))
            x <- character(0)

            updateCheckboxGroupInput(session, inputId = "timecheck",
            choices = unique(bindata()$Time.of.Kill),
            selected = unique(bindata()$Time.of.Kill),
            inline = TRUE)
            )

            #Creates the observed Age

            observeEvent(input$timecheck,

            x <- input$timecheck
            if (is.null(x))
            x <- character(0)

            updateCheckboxGroupInput(session, inputId = "agecheck",
            choices = unique(bindata()$Age),
            selected = unique(bindata()$Age),
            inline = TRUE)
            )

            #Creates the observed dates and suppresses warnings from the min max

            observeEvent(input$agecheck,

            x <- input$agecheck
            if (is.null(x))
            x <- character(0)

            #And update the date range values to match those of the dataset

            updateDateRangeInput(
            session = session,
            inputId = "inDateRange",
            start = min(suppressWarnings(bindata()$Accident.Date)),
            end = max(suppressWarnings(bindata()$Accident.Date))
            )
            )


            output$txt <- renderText(nrow(data1()))


            )


            My only change is to use bindata() to update checkboxs, this will force all to appear so no animal is pre-filtered.
            Therefore, my solution is to renounce to create dynamic checks and show all from the very first time you select an animal.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 23 at 7:07









            LocoGrisLocoGris

            2,7832828




            2,7832828












            • Close but I solved it. Thanks for the advice.

              – Jayman McAllister
              Mar 24 at 0:50

















            • Close but I solved it. Thanks for the advice.

              – Jayman McAllister
              Mar 24 at 0:50
















            Close but I solved it. Thanks for the advice.

            – Jayman McAllister
            Mar 24 at 0:50





            Close but I solved it. Thanks for the advice.

            – Jayman McAllister
            Mar 24 at 0:50













            0














            The solution was rather obvious. The desired effect was obtained by just placing the updateinputs inside of observe() rather than trying to observe the upstream inputs as they change. This was applied to all upstream updateinputs.



             observe(

            x <- input$agecheck
            if (is.null(x))
            x <- character(0)

            #And update the date range values to match those of the dataset

            updateDateRangeInput(
            session = session,
            inputId = "inDateRange",
            start = suppressWarnings(min(agedata()$Accident.Date)),
            end = suppressWarnings(max(agedata()$Accident.Date))
            )
            )


            This solved the problem!






            share|improve this answer



























              0














              The solution was rather obvious. The desired effect was obtained by just placing the updateinputs inside of observe() rather than trying to observe the upstream inputs as they change. This was applied to all upstream updateinputs.



               observe(

              x <- input$agecheck
              if (is.null(x))
              x <- character(0)

              #And update the date range values to match those of the dataset

              updateDateRangeInput(
              session = session,
              inputId = "inDateRange",
              start = suppressWarnings(min(agedata()$Accident.Date)),
              end = suppressWarnings(max(agedata()$Accident.Date))
              )
              )


              This solved the problem!






              share|improve this answer

























                0












                0








                0







                The solution was rather obvious. The desired effect was obtained by just placing the updateinputs inside of observe() rather than trying to observe the upstream inputs as they change. This was applied to all upstream updateinputs.



                 observe(

                x <- input$agecheck
                if (is.null(x))
                x <- character(0)

                #And update the date range values to match those of the dataset

                updateDateRangeInput(
                session = session,
                inputId = "inDateRange",
                start = suppressWarnings(min(agedata()$Accident.Date)),
                end = suppressWarnings(max(agedata()$Accident.Date))
                )
                )


                This solved the problem!






                share|improve this answer













                The solution was rather obvious. The desired effect was obtained by just placing the updateinputs inside of observe() rather than trying to observe the upstream inputs as they change. This was applied to all upstream updateinputs.



                 observe(

                x <- input$agecheck
                if (is.null(x))
                x <- character(0)

                #And update the date range values to match those of the dataset

                updateDateRangeInput(
                session = session,
                inputId = "inDateRange",
                start = suppressWarnings(min(agedata()$Accident.Date)),
                end = suppressWarnings(max(agedata()$Accident.Date))
                )
                )


                This solved the problem!







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 24 at 0:50









                Jayman McAllisterJayman McAllister

                134




                134



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309078%2fissue-with-multiple-reactive-filters-and-updateselectinputs-strange-behavior%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript