selectInput within conditionalPanel not updating data/plot in server

The code below is commented to show where I think my problem is. In essence, the data or plot is not updating when I choose from the dropdown list (selectInput) when it is within the conditionalPanel.

https://nic01a.shinyapps.io/test/

However, it all works when it is outside of the conditionalPanel. I think I am missing something with specifying reactivity somewhere, but can't work it out from all the searches I have done so far. Thanks for your help.

#selectInput selection does not update data/plot when put within conditionalPanel
#

library(shiny)
library(shinythemes)
library(ggplot2)
library(ggthemes)
library(dplyr)
library(plotly)
library(shinycustomloader)
# Define UI for application
ui <- fluidPage(
   
   # Application title
   titlePanel("selectInput within conditionPanel not updating"),
   
   # Sidebar with a slider input for number of bins 
    sidebarLayout(position = "right",
       sidebarPanel(
          sliderInput("yr","Year:",
                min = 1997, max = 2006,
                value = c(2001,2006), sep = "") ,
          selectInput("loc", "Jurisdiction",
                c("Aus", "ACT", "NSW", "NT",
                "Qld", "Tas", "SA", "Vic", "WA"),"Aus") ,
          radioButtons("DropAllB", "Variable for dropdown list:",
                       choices = c(
                          "Type",
                          "Sex"
                       ),inline = T,
                       selected = c("Type")
          ),

#######checkboxGroupInput works, but selectInput does not - selection does not change the data############
          conditionalPanel(
                condition = "input.DropAllB == 'Type'",
         #This doesn't update
                  selectInput("int", label = NULL,
                        choices = c("All types",
                        "Accidental"),
                        selected = c("All types") ),
         #This updates
         checkboxGroupInput("x", label = "Sex:",
                        choices = c("All", "Female", "Male"),
                        selected = c("All")  )
             ),

          conditionalPanel(
               condition = "input.DropAllB == 'Sex'",
         #This doesn't update
               selectInput("x", label = NULL,
                        choices = c("All", "Female", "Male"),
                        selected = c("All") ) ),

          conditionalPanel(
               condition = "input.DropAllB == 'Sex'",
         #This updates
               checkboxGroupInput(
                 "int", label = "Type:",
                 c("All types",
                   "Accidental"),
                 selected = c("All types") )
           )
################### Problem is in this section above ##########################

   #This works
          # selectInput("x", "Sex",
          #     c("All"="All", "Females"="Female", "Males"="Male"),"All") ,
          # checkboxGroupInput("int", "Type",
          #  c("Accidental","All types"),"All types")
       ) ,
      mainPanel(
   #Show a plot
         withLoader(plotlyOutput("test", width = "100%", height = "600px"), type = "html", loader = "loader4")
      )
   )
)

# Define server logic
server <- function(input, output, session) {
observe ({
   output$test <- renderPlotly({
      df <- readcsv("test.csv")
      plotdata <- subset(df, subset=(location %in% input$loc & 
                sex %in% input$x & type %in% input$int))
#     print(input$yr)

     p <- ggplot(plotdata) + 
       aes(x = year, y = n, colour=sex, linetype=type, group=1,
           text = paste0(
              "Year: ", year,
              "<br>Number: ", n,
              "<br>Sex: ", sex,
              "<br>Location: ", location)) +
       geom_line() +
       scale_color_manual(values = c("All"="black", "Male"="blue", "Female"="red")) +
       scale_linetype_manual(values = c("All types"="solid", "Accidental"="twodash")) +
       xlim(input$yr)

     ggplotly(p, tooltip = "text") %>%
        layout(legend = list(y = 0.95, yanchor = "top"), margin = list(b = 100, l = 100)) %>% 
        config(displaylogo=F, modeBarButtonsToRemove = list("sendDataToCloud","zoom2d","pan2d","select2d","lasso2d",
                                                            "zoomIn2d","zoomOut2d","autoScale2d","hoverClosestCartesian",
                                                            "hoverCompareCartesian", "resetScale2d", "toggleSpikelines"))
   })
})
}

# Run the application 
shinyApp(ui = ui, server = server)

Hi @Nic. Can you upload the file test.rds. I can't test your code without this file.

1 Like

csv file of test data below.

"Obs","type","location","sex","n","year"
"1","Accidental","ACT","All",0.833835941749618,1997
"2","All types","ACT","All",-0.120619686993844,1997
"3","Accidental","Aus","All",-0.647381610643707,1997
"4","All types","Aus","All",0.18183270522856,1997
"5","Accidental","NSW","All",-0.664073026585429,1997
"6","All types","NSW","All",-0.920659114148146,1997
"7","Accidental","NT","All",-1.02402010464512,1997
"8","All types","NT","All",0.249284093806111,1997
"9","Accidental","Qld","All",-0.961658875220199,1997
"10","All types","Qld","All",0.0843117626977634,1997
"11","Accidental","SA","All",0.817709420233886,1997
"12","All types","SA","All",0.932643069315902,1997
"13","Accidental","Tas","All",1.59185298275046,1997
"14","All types","Tas","All",1.00915288560135,1997
"15","Accidental","Vic","All",-0.232605123494972,1997
"16","All types","Vic","All",0.628321369499324,1997
"17","Accidental","WA","All",0.936285286251242,1997
"18","All types","WA","All",-0.677551406842824,1997
"19","Accidental","ACT","Female",0.80985790258086,1997
"20","All types","ACT","Female",-0.854104144601367,1997
"21","Accidental","Aus","Female",-1.11192679383315,1997
"22","All types","Aus","Female",-0.445764522280486,1997
"23","Accidental","NSW","Female",-0.0629540102527476,1997
"24","All types","NSW","Female",0.981707414003929,1997
"25","Accidental","NT","Female",0.945057713112728,1997
"26","All types","NT","Female",-0.0932428195329441,1997
"27","Accidental","Qld","Female",0.231946086510698,1997
"28","All types","Qld","Female",1.56296784644191,1997
"29","Accidental","SA","Female",1.21169565117549,1997
"30","All types","SA","Female",-0.380040319570079,1997
"31","Accidental","Tas","Female",0.212235496033144,1997
"32","All types","Tas","Female",-0.435899798211214,1997
"33","Accidental","Vic","Female",0.043017966220872,1997
"34","All types","Vic","Female",1.46712131072724,1997
"35","Accidental","WA","Female",-0.229925487538695,1997
"36","All types","WA","Female",0.0409195144459224,1997
"37","Accidental","ACT","Male",0.670003423819181,1997
"38","All types","ACT","Male",0.0947745727059714,1997
"39","Accidental","Aus","Male",1.52410933376339,1997
"40","All types","Aus","Male",-1.38816371062265,1997
"41","Accidental","NSW","Male",-0.45601680240263,1997
"42","All types","NSW","Male",-0.0710358163652373,1997
"43","Accidental","NT","Male",-0.763747559224193,1997
"44","All types","NT","Male",-0.500311589204291,1997
"45","Accidental","Qld","Male",-0.832172556257927,1997
"46","All types","Qld","Male",-0.430567869897526,1997
"47","Accidental","SA","Male",1.29772058783522,1997
"48","All types","SA","Male",0.589491729115224,1997
"49","Accidental","Tas","Male",0.847928315838451,1997
"50","All types","Tas","Male",-1.87929722442149,1997
"51","Accidental","Vic","Male",-0.807640319128246,1997
"52","All types","Vic","Male",-0.366317512106723,1997
"53","Accidental","WA","Male",0.596994931087095,1997
"54","All types","WA","Male",-0.52204661280605,1997
"55","Accidental","ACT","All",0.434529094711909,1998
"56","All types","ACT","All",2.17677726572489,1998
"57","Accidental","Aus","All",0.833122399800684,1998
"58","All types","Aus","All",-1.82542621814887,1998
"59","Accidental","NSW","All",0.212379315309069,1998
"60","All types","NSW","All",0.058838784318945,1998
"61","Accidental","NT","All",-1.93136243834133,1998
"62","All types","NT","All",0.381668669641175,1998
"63","Accidental","Qld","All",0.750157603928013,1998
"64","All types","Qld","All",0.522603678840245,1998
"65","Accidental","SA","All",0.72009825326824,1998
"66","All types","SA","All",0.19071579071505,1998
"67","Accidental","Tas","All",0.68886847912332,1998
"68","All types","Tas","All",0.71879352781036,1998
"69","Accidental","Vic","All",-1.80884293885866,1998
"70","All types","Vic","All",1.51094891385361,1998
"71","Accidental","WA","All",-0.247148333861387,1998
"72","All types","WA","All",-0.140601329652705,1998
"73","Accidental","ACT","Female",0.166660699890813,1998
"74","All types","ACT","Female",-0.711869360769599,1998
"75","Accidental","Aus","Female",0.120719657280186,1998
"76","All types","Aus","Female",-0.764198036417469,1998
"77","Accidental","NSW","Female",0.279255063113089,1998
"78","All types","NSW","Female",-0.117351855099619,1998
"79","Accidental","NT","Female",-0.503884334450632,1998
"80","All types","NT","Female",-1.79735524253143,1998
"81","Accidental","Qld","Female",-0.888794835321906,1998
"82","All types","Qld","Female",1.23429685211526,1998
"83","Accidental","SA","Female",-0.53929105138015,1998
"84","All types","SA","Female",0.852191737314607,1998
"85","Accidental","Tas","Female",-0.331920335016578,1998
"86","All types","Tas","Female",0.0189292800913662,1998
"87","Accidental","Vic","Female",0.409180843168896,1998
"88","All types","Vic","Female",-0.502957681576835,1998
"89","Accidental","WA","Female",0.41123220710634,1998
"90","All types","WA","Female",-0.953372950944086,1998
"91","Accidental","ACT","Male",0.496979085955768,1998
"92","All types","ACT","Male",-1.75435935625047,1998
"93","Accidental","Aus","Male",-0.670529722161839,1998
"94","All types","Aus","Male",0.067805865024755,1998
"95","Accidental","NSW","Male",-0.847193182633389,1998
"96","All types","NSW","Male",-1.48212333645141,1998
"97","Accidental","NT","Male",-0.154398698090642,1998
"98","All types","NT","Male",-0.439897061760323,1998
"99","Accidental","Qld","Male",0.359141905166491,1998
"100","All types","Qld","Male",-0.876515280312217,1998
"101","Accidental","SA","Male",-0.275328509177008,1998
"102","All types","SA","Male",0.275924082288077,1998
"103","Accidental","Tas","Male",0.345862797007844,1998
"104","All types","Tas","Male",0.239273242667421,1998
"105","Accidental","Vic","Male",1.15080497127986,1998
"106","All types","Vic","Male",0.0470551052727157,1998
"107","Accidental","WA","Male",1.77038015095705,1998
"108","All types","WA","Male",0.474986664553315,1998
"109","Accidental","ACT","All",-0.113415986545689,1999
"110","All types","ACT","All",0.959411310670188,1999
"111","Accidental","Aus","All",-0.354522513797136,1999
"112","All types","Aus","All",0.618225249041163,1999
"113","Accidental","NSW","All",-0.762125648560863,1999
"114","All types","NSW","All",0.660670720778041,1999
"115","Accidental","NT","All",0.63977155759521,1999
"116","All types","NT","All",0.36840725024905,1999
"117","Accidental","Qld","All",-1.0317837728559,1999
"118","All types","Qld","All",0.841790096191332,1999
"119","Accidental","SA","All",-0.667563674185064,1999
"120","All types","SA","All",-0.624909100503548,1999
"121","Accidental","Tas","All",0.277942923089952,1999
"122","All types","Tas","All",0.283521637836949,1999
"123","Accidental","Vic","All",0.971572950658199,1999
"124","All types","Vic","All",-0.783476253230608,1999
"125","Accidental","WA","All",1.3106188328484,1999
"126","All types","WA","All",-0.227472702498605,1999
"127","Accidental","ACT","Female",0.831231422292255,1999
"128","All types","ACT","Female",-0.339819236643668,1999
"129","Accidental","Aus","Female",-0.673360765499065,1999
"130","All types","Aus","Female",1.01801444667,1999
"131","Accidental","NSW","Female",-0.583190573653638,1999
"132","All types","NSW","Female",0.7058882192036,1999
"133","Accidental","NT","Female",-0.843801342015949,1999
"134","All types","NT","Female",-2.61038071457697,1999
"135","Accidental","Qld","Female",-1.14489289690637,1999
"136","All types","Qld","Female",-2.51744695711244,1999
"137","Accidental","SA","Female",1.46943673898704,1999
"138","All types","SA","Female",-3.36315481483695,1999
"139","Accidental","Tas","Female",-0.858961443404554,1999
"140","All types","Tas","Female",-0.651991603705234,1999
"141","Accidental","Vic","Female",-0.714569903771084,1999
"142","All types","Vic","Female",0.115988419731603,1999
"143","Accidental","WA","Female",-1.2221688821241,1999
"144","All types","WA","Female",-0.646681556785749,1999
"145","Accidental","ACT","Male",0.100437807416464,1999
"146","All types","ACT","Male",-0.0223709753186437,1999
"147","Accidental","Aus","Male",0.0670427976402884,1999
"148","All types","Aus","Male",0.152870892334271,1999
"149","Accidental","NSW","Male",0.479030586488211,1999
"150","All types","NSW","Male",-0.80696943046744,1999
"151","Accidental","NT","Male",-0.882435739482629,1999
"152","All types","NT","Male",0.433249959970388,1999
"153","Accidental","Qld","Male",-0.810702614707261,1999
"154","All types","Qld","Male",-0.260277272696645,1999
"155","Accidental","SA","Male",-1.8975531958661,1999
"156","All types","SA","Male",1.83448124094988,1999
"157","Accidental","Tas","Male",-0.667278407140097,1999
"158","All types","Tas","Male",0.51426574398204,1999
"159","Accidental","Vic","Male",-0.739859628964203,1999
"160","All types","Vic","Male",0.111354239238404,1999
"161","Accidental","WA","Male",0.154760438955411,1999
"162","All types","WA","Male",1.91539523184327,1999
"163","Accidental","ACT","All",-0.785034002272909,2000
"164","All types","ACT","All",-0.0201869052716544,2000
"165","Accidental","Aus","All",1.28611949928528,2000
"166","All types","Aus","All",1.19011700329656,2000
"167","Accidental","NSW","All",0.71322533305249,2000
"168","All types","NSW","All",-0.0626588383818474,2000
"169","Accidental","NT","All",-1.03152817019537,2000
"170","All types","NT","All",-0.00983619200756833,2000
"171","Accidental","Qld","All",-0.996647160675392,2000
"172","All types","Qld","All",0.221664370054173,2000
"173","Accidental","SA","All",-0.167171848917247,2000
"174","All types","SA","All",-0.190837565069678,2000
"175","Accidental","Tas","All",0.321767014552299,2000
"176","All types","Tas","All",0.601368946629396,2000
"177","Accidental","Vic","All",-0.271362993798983,2000
"178","All types","Vic","All",1.15319264623737,2000
"179","Accidental","WA","All",0.960372075640803,2000
"180","All types","WA","All",-1.15991893709749,2000
"181","Accidental","ACT","Female",-0.854058675872341,2000
"182","All types","ACT","Female",-1.69141213354885,2000
"183","Accidental","Aus","Female",0.169472841736644,2000
"184","All types","Aus","Female",0.539704978202334,2000
"185","Accidental","NSW","Female",1.25611158715672,2000
"186","All types","NSW","Female",2.66350711716833,2000
"187","Accidental","NT","Female",-1.64978339342021,2000
"188","All types","NT","Female",0.44186248881615,2000
"189","Accidental","Qld","Female",1.12914156483274,2000
"190","All types","Qld","Female",-0.176652767673149,2000
"191","Accidental","SA","Female",0.322649956408592,2000
"192","All types","SA","Female",-0.0365611715465617,2000
"193","Accidental","Tas","Female",-0.0990594800198162,2000
"194","All types","Tas","Female",0.118969247713339,2000
"195","Accidental","Vic","Female",-0.38261086623889,2000
"196","All types","Vic","Female",1.43116236866693,2000
"197","Accidental","WA","Female",-0.92875248561611,2000
"198","All types","WA","Female",-0.14547813045161,2000
"199","Accidental","ACT","Male",0.0880922587263316,2000
"200","All types","ACT","Male",-0.580824962997755,2000
"201","Accidental","Aus","Male",0.165918353537191,2000
"202","All types","Aus","Male",1.54320972668763,2000
"203","Accidental","NSW","Male",-1.6221821910502,2000
"204","All types","NSW","Male",0.700805656461732,2000
"205","Accidental","NT","Male",1.56502686293708,2000
"206","All types","NT","Male",0.632418289017322,2000
"207","Accidental","Qld","Male",0.650020878887108,2000
"208","All types","Qld","Male",1.71489508216689,2000
"209","Accidental","SA","Male",0.0056152556161307,2000
"210","All types","SA","Male",1.41880436512713,2000
"211","Accidental","Tas","Male",0.903922640864779,2000
"212","All types","Tas","Male",-0.698464817843896,2000
"213","Accidental","Vic","Male",1.93950008483736,2000
"214","All types","Vic","Male",0.116990281899387,2000
"215","Accidental","WA","Male",0.411094936622166,2000
"216","All types","WA","Male",-1.24615600926596,2000
"217","Accidental","ACT","All",0.58835187955225,2001
"218","All types","ACT","All",0.239465135156185,2001
"219","Accidental","Aus","All",-1.06679134524661,2001
"220","All types","Aus","All",-1.68328578418794,2001
"221","Accidental","NSW","All",0.480296398066869,2001
"222","All types","NSW","All",2.18244335080563,2001
"223","Accidental","NT","All",-0.589141396319926,2001
"224","All types","NT","All",2.07353808628058,2001
"225","Accidental","Qld","All",-0.371220530225221,2001
"226","All types","Qld","All",-0.659153556139946,2001
"227","Accidental","SA","All",-0.123249403755242,2001
"228","All types","SA","All",-0.471003091253359,2001
"229","Accidental","Tas","All",1.65719884126442,2001
"230","All types","Tas","All",-2.16481554642885,2001
"231","Accidental","Vic","All",1.03808684350363,2001
"232","All types","Vic","All",0.69617442512342,2001
"233","Accidental","WA","All",-0.56627488323716,2001
"234","All types","WA","All",0.108367504776535,2001
"235","Accidental","ACT","Female",1.42298755079299,2001
"236","All types","ACT","Female",-0.37028184224032,2001
"237","Accidental","Aus","Female",1.36537268575273,2001
"238","All types","Aus","Female",-0.77424014050646,2001
"239","Accidental","NSW","Female",-0.142216777177965,2001
"240","All types","NSW","Female",0.208327797860096,2001
"241","Accidental","NT","Female",-0.783603264857525,2001
"242","All types","NT","Female",-0.842864546720027,2001
"243","Accidental","Qld","Female",-0.429058020069383,2001
"244","All types","Qld","Female",0.602693280607775,2001
"245","Accidental","SA","Female",0.781599824528354,2001
"246","All types","SA","Female",-1.26160673734513,2001
"247","Accidental","Tas","Female",0.254128783693118,2001
"248","All types","Tas","Female",-2.12351610936751,2001
"249","Accidental","Vic","Female",0.0442259148611196,2001
"250","All types","Vic","Female",0.575996279187762,2001
"251","Accidental","WA","Female",0.51639425755887,2001
"252","All types","WA","Female",-0.428380552216511,2001
"253","Accidental","ACT","Male",-0.668178124695837,2001
"254","All types","ACT","Male",-0.808727146636562,2001
"255","Accidental","Aus","Male",-1.83757269961405,2001
"256","All types","Aus","Male",0.174384031956185,2001
"257","Accidental","NSW","Male",0.696208002943405,2001
"258","All types","NSW","Male",0.26649139241514,2001
"259","Accidental","NT","Male",-0.395205955067404,2001
"260","All types","NT","Male",0.223540169843899,2001
"261","Accidental","Qld","Male",-0.895831071898762,2001
"262","All types","Qld","Male",-0.0301731557869422,2001
"263","Accidental","SA","Male",-0.407641829698753,2001
"264","All types","SA","Male",2.28193180672161,2001
"265","Accidental","Tas","Male",0.668935870197032,2001
"266","All types","Tas","Male",-2.34693874368946,2001
"267","Accidental","Vic","Male",-1.8091789821639,2001
"268","All types","Vic","Male",-0.359878478982617,2001
"269","Accidental","WA","Male",-1.56466341788251,2001
"270","All types","WA","Male",0.79620159643184,2001
"271","Accidental","ACT","All",0.755059118746335,2002
"272","All types","ACT","All",-0.912590352636025,2002
"273","Accidental","Aus","All",0.995350992639875,2002
"274","All types","Aus","All",-0.435342668043482,2002
"275","Accidental","NSW","All",1.2252274200526,2002
"276","All types","NSW","All",-1.50371043876736,2002
"277","Accidental","NT","All",1.24735294696815,2002
"278","All types","NT","All",1.39176949673746,2002
"279","Accidental","Qld","All",0.289763143887162,2002
"280","All types","Qld","All",0.6878107474452,2002
"281","Accidental","SA","All",1.26682109802027,2002
"282","All types","SA","All",-0.64319335101922,2002
"283","Accidental","Tas","All",-0.497841629595967,2002
"284","All types","Tas","All",0.372888974514807,2002
"285","Accidental","Vic","All",1.4355623606906,2002
"286","All types","Vic","All",-1.51631741951432,2002
"287","Accidental","WA","All",1.94375777986363,2002
"288","All types","WA","All",0.331267289824423,2002
"289","Accidental","ACT","Female",-2.15936061458786,2002
"290","All types","ACT","Female",-2.03564319006183,2002
"291","Accidental","Aus","Female",0.322357695209053,2002
"292","All types","Aus","Female",1.53641013355815,2002
"293","Accidental","NSW","Female",-0.159335016295463,2002
"294","All types","NSW","Female",-0.109151464533961,2002
"295","Accidental","NT","Female",-1.24779027142107,2002
"296","All types","NT","Female",1.8398026676572,2002
"297","Accidental","Qld","Female",1.23398570452186,2002
"298","All types","Qld","Female",-1.03176032213005,2002
"299","Accidental","SA","Female",-0.965230700149471,2002
"300","All types","SA","Female",-1.33170477480673,2002
"301","Accidental","Tas","Female",-0.403707821975891,2002
"302","All types","Tas","Female",1.62366628717395,2002
"303","Accidental","Vic","Female",1.74221148764148,2002
"304","All types","Vic","Female",-1.81796036014636,2002
"305","Accidental","WA","Female",1.32790607338559,2002
"306","All types","WA","Female",0.0377400654558649,2002
"307","Accidental","ACT","Male",0.720567113086886,2002
"308","All types","ACT","Male",0.579701356499661,2002
"309","Accidental","Aus","Male",0.288180763274926,2002
"310","All types","Aus","Male",0.275391786820655,2002
"311","Accidental","NSW","Male",-0.241345826246716,2002
"312","All types","NSW","Male",0.403760056826509,2002
"313","Accidental","NT","Male",-1.50740248048461,2002
"314","All types","NT","Male",1.08790838006935,2002
"315","Accidental","Qld","Male",0.0147202045507907,2002
"316","All types","Qld","Male",-1.56770784204221,2002
"317","Accidental","SA","Male",1.3906921779351,2002
"318","All types","SA","Male",-0.242145601083445,2002
"319","Accidental","Tas","Male",0.67256165341086,2002
"320","All types","Tas","Male",-1.66354931367659,2002
"321","Accidental","Vic","Male",2.25188450900361,2002
"322","All types","Vic","Male",0.247536777972801,2002
"323","Accidental","WA","Male",0.238068931878711,2002
"324","All types","WA","Male",1.37540642791581,2002
"325","Accidental","ACT","All",-0.17432588976693,2003
"326","All types","ACT","All",1.56813953615047,2003
"327","Accidental","Aus","All",0.689242062256142,2003
"328","All types","Aus","All",-0.669545273011797,2003
"329","Accidental","NSW","All",1.67120355000803,2003
"330","All types","NSW","All",0.849358680082387,2003
"331","Accidental","NT","All",0.435733792179526,2003
"332","All types","NT","All",-1.07431114453702,2003
"333","Accidental","Qld","All",0.294891756655463,2003
"334","All types","Qld","All",-0.333866187360341,2003
"335","Accidental","SA","All",-0.302490545486201,2003
"336","All types","SA","All",-0.762692732538283,2003
"337","Accidental","Tas","All",0.599302349237248,2003
"338","All types","Tas","All",-0.306271325561434,2003
"339","Accidental","Vic","All",-0.498947654420169,2003
"340","All types","Vic","All",0.664553527170675,2003
"341","Accidental","WA","All",0.530100916196915,2003
"342","All types","WA","All",1.27832345358513,2003
"343","Accidental","ACT","Female",1.97181513318317,2003
"344","All types","ACT","Female",-0.579617879354435,2003
"345","Accidental","Aus","Female",0.930200794609487,2003
"346","All types","Aus","Female",0.70377825385549,2003
"347","Accidental","NSW","Female",1.35709318563417,2003
"348","All types","NSW","Female",-1.09001364736732,2003
"349","Accidental","NT","Female",0.416166021021885,2003
"350","All types","NT","Female",-0.774942207346313,2003
"351","Accidental","Qld","Female",-0.319561208109145,2003
"352","All types","Qld","Female",0.476658312565063,2003
"353","Accidental","SA","Female",1.44920196361946,2003
"354","All types","SA","Female",1.2835569021386,2003
"355","Accidental","Tas","Female",-1.64454570577546,2003
"356","All types","Tas","Female",-0.111380694352394,2003
"357","Accidental","Vic","Female",1.40252382414935,2003
"358","All types","Vic","Female",0.646742464632773,2003
"359","Accidental","WA","Female",-0.0926579783499479,2003
"360","All types","WA","Female",-0.139677343002336,2003
"361","Accidental","ACT","Male",-0.760219538448082,2003
"362","All types","ACT","Male",-0.25541164348065,2003
"363","Accidental","Aus","Male",1.46208711847181,2003
"364","All types","Aus","Male",-1.50646839157298,2003
"365","Accidental","NSW","Male",-1.22779246963933,2003
"366","All types","NSW","Male",0.18611506028508,2003
"367","Accidental","NT","Male",-0.684191307248005,2003
"368","All types","NT","Male",0.466249964433231,2003
"369","Accidental","Qld","Male",0.823207822005843,2003
"370","All types","Qld","Male",1.15765826339916,2003
"371","Accidental","SA","Male",1.66788354932096,2003
"372","All types","SA","Male",0.256352312028212,2003
"373","Accidental","Tas","Male",-0.226624258283851,2003
"374","All types","Tas","Male",-1.69835539286975,2003
"375","Accidental","Vic","Male",-0.615029024723218,2003
"376","All types","Vic","Male",1.04544603807997,2003
"377","Accidental","WA","Male",-0.379185972109714,2003
"378","All types","WA","Male",0.448907995491614,2003
"379","Accidental","ACT","All",-1.3382868081351,2004
"380","All types","ACT","All",-1.43815914576472,2004
"381","Accidental","Aus","All",-0.215697194360585,2004
"382","All types","Aus","All",-0.503080670852275,2004
"383","Accidental","NSW","All",-1.48067612466296,2004
"384","All types","NSW","All",0.766047608383607,2004
"385","Accidental","NT","All",-1.7354114859839,2004
"386","All types","NT","All",-0.511802895724012,2004
"387","Accidental","Qld","All",0.277987996817196,2004
"388","All types","Qld","All",-1.03481050070569,2004
"389","Accidental","SA","All",1.75225257410093,2004
"390","All types","SA","All",0.166943696958452,2004
"391","Accidental","Tas","All",0.625704986803278,2004
"392","All types","Tas","All",-0.894176588613961,2004
"393","Accidental","Vic","All",0.489626347906423,2004
"394","All types","Vic","All",-1.02237258620813,2004
"395","Accidental","WA","All",-0.0460041285816493,2004
"396","All types","WA","All",0.00791688940042979,2004
"397","Accidental","ACT","Female",-1.05421163032466,2004
"398","All types","ACT","Female",0.10378686195438,2004
"399","Accidental","Aus","Female",0.155313773487497,2004
"400","All types","Aus","Female",0.147650972660231,2004
"401","Accidental","NSW","Female",0.181024480243925,2004
"402","All types","NSW","Female",-0.021367271339616,2004
"403","Accidental","NT","Female",-2.93831626251876,2004
"404","All types","NT","Female",0.536663434628294,2004
"405","Accidental","Qld","Female",0.615337764781647,2004
"406","All types","Qld","Female",-0.59359042440266,2004
"407","Accidental","SA","Female",1.69448134059625,2004
"408","All types","SA","Female",0.568632773746128,2004
"409","Accidental","Tas","Female",2.08829074086909,2004
"410","All types","Tas","Female",0.317492878439932,2004
"411","Accidental","Vic","Female",0.709798066770461,2004
"412","All types","Vic","Female",0.177122537638918,2004
"413","Accidental","WA","Female",0.314790115915004,2004
"414","All types","WA","Female",0.637994220357825,2004
"415","Accidental","ACT","Male",-1.5904603773217,2004
"416","All types","ACT","Male",-0.454986516230712,2004
"417","Accidental","Aus","Male",-0.771026588791625,2004
"418","All types","Aus","Male",0.41230557353939,2004
"419","Accidental","NSW","Male",1.36468896267018,2004
"420","All types","NSW","Male",1.80662848596579,2004
"421","Accidental","NT","Male",0.330250255734619,2004
"422","All types","NT","Male",0.320248291768745,2004
"423","Accidental","Qld","Male",-1.2429819493434,2004
"424","All types","Qld","Male",2.74896638055124,2004
"425","Accidental","SA","Male",-1.25769907273567,2004
"426","All types","SA","Male",0.476403957348298,2004
"427","Accidental","Tas","Male",-0.206159368879537,2004
"428","All types","Tas","Male",-1.15264154992357,2004
"429","Accidental","Vic","Male",1.63921710882241,2004
"430","All types","Vic","Male",-1.66443024889374,2004
"431","Accidental","WA","Male",0.748192379076359,2004
"432","All types","WA","Male",-1.5736762657975,2004
"433","Accidental","ACT","All",-0.170166537681211,2005
"434","All types","ACT","All",-2.10751185146909,2005
"435","Accidental","Aus","All",-1.05744411329106,2005
"436","All types","Aus","All",-1.21352160942111,2005
"437","Accidental","NSW","All",1.51757467852764,2005
"438","All types","NSW","All",-0.984823153669567,2005
"439","Accidental","NT","All",-0.278636131609082,2005
"440","All types","NT","All",-0.520377328579822,2005
"441","Accidental","Qld","All",-0.720049045757275,2005
"442","All types","Qld","All",-0.802650696862747,2005
"443","Accidental","SA","All",-0.870948559547011,2005
"444","All types","SA","All",1.69873151870795,2005
"445","Accidental","Tas","All",1.62922265540839,2005
"446","All types","Tas","All",-1.49303673633651,2005
"447","Accidental","Vic","All",-1.10186230664651,2005
"448","All types","Vic","All",-1.03608842302499,2005
"449","Accidental","WA","All",-2.03581120208551,2005
"450","All types","WA","All",-0.70644956558232,2005
"451","Accidental","ACT","Female",-0.537257390890119,2005
"452","All types","ACT","Female",1.24431667947033,2005
"453","Accidental","Aus","Female",0.990646752168185,2005
"454","All types","Aus","Female",0.125908708516891,2005
"455","Accidental","NSW","Female",0.0657160953462844,2005
"456","All types","NSW","Female",1.05115440579553,2005
"457","Accidental","NT","Female",-1.2891128013209,2005
"458","All types","NT","Female",-0.611832082558643,2005
"459","Accidental","Qld","Female",-0.964357404458285,2005
"460","All types","Qld","Female",0.0404317222692095,2005
"461","Accidental","SA","Female",0.691852262572433,2005
"462","All types","SA","Female",-0.126349722971442,2005
"463","Accidental","Tas","Female",-0.615405053340528,2005
"464","All types","Tas","Female",-1.53964491379293,2005
"465","Accidental","Vic","Female",0.719547447903148,2005
"466","All types","Vic","Female",0.580563159022573,2005
"467","Accidental","WA","Female",0.675931372084582,2005
"468","All types","WA","Female",-1.3082758659296,2005
"469","Accidental","ACT","Male",0.395347165457821,2005
"470","All types","ACT","Male",-1.51148916255327,2005
"471","Accidental","Aus","Male",-1.90601477198791,2005
"472","All types","Aus","Male",0.759622810618918,2005
"473","Accidental","NSW","Male",0.356615830179692,2005
"474","All types","NSW","Male",1.98980400982779,2005
"475","Accidental","NT","Male",2.02881033996834,2005
"476","All types","NT","Male",0.934462761698631,2005
"477","Accidental","Qld","Male",0.510914477010257,2005
"478","All types","Qld","Male",-0.106586445157961,2005
"479","Accidental","SA","Male",0.144927593952126,2005
"480","All types","SA","Male",1.03999777241263,2005
"481","Accidental","Tas","Male",-1.06972893109726,2005
"482","All types","Tas","Male",0.0340429581075505,2005
"483","Accidental","Vic","Male",1.41485876609096,2005
"484","All types","Vic","Male",-0.348482723591928,2005
"485","Accidental","WA","Male",-1.22725817221032,2005
"486","All types","WA","Male",-0.286037074700486,2005
"487","Accidental","ACT","All",-0.886229088731657,2006
"488","All types","ACT","All",-0.14628773666585,2006
"489","Accidental","Aus","All",-0.557594444777508,2006
"490","All types","Aus","All",0.803550742499854,2006
"491","Accidental","NSW","All",0.9880423519811,2006
"492","All types","NSW","All",-0.744601493306065,2006
"493","Accidental","NT","All",-1.75022300538845,2006
"494","All types","NT","All",-0.631629017356259,2006
"495","Accidental","Qld","All",-1.80939124006108,2006
"496","All types","Qld","All",0.431994897436684,2006
"497","Accidental","SA","All",-0.568060469202159,2006
"498","All types","SA","All",-2.24875800065957,2006
"499","Accidental","Tas","All",-1.28943615177166,2006
"500","All types","Tas","All",-1.16319567561442,2006
"501","Accidental","Vic","All",-1.80169100101112,2006
"502","All types","Vic","All",1.27498031207594,2006
"503","Accidental","WA","All",0.222396316725832,2006
"504","All types","WA","All",0.340799201684533,2006
"505","Accidental","ACT","Female",-0.583830847477096,2006
"506","All types","ACT","Female",-0.20901501418797,2006
"507","Accidental","Aus","Female",0.271373863811749,2006
"508","All types","Aus","Female",0.295618547801506,2006
"509","Accidental","NSW","Female",1.85818832368189,2006
"510","All types","NSW","Female",-1.03398277539689,2006
"511","Accidental","NT","Female",0.592778535226769,2006
"512","All types","NT","Female",0.341262053886091,2006
"513","Accidental","Qld","Female",-0.866800157588116,2006
"514","All types","Qld","Female",0.967009807716849,2006
"515","Accidental","SA","Female",-1.65435766721346,2006
"516","All types","SA","Female",1.56124011886502,2006
"517","Accidental","Tas","Female",0.0392702959218667,2006
"518","All types","Tas","Female",-1.46501258571979,2006
"519","Accidental","Vic","Female",-0.0616827425032375,2006
"520","All types","Vic","Female",1.42754446397041,2006
"521","Accidental","WA","Female",0.39130278158913,2006
"522","All types","WA","Female",1.44362438764878,2006
"523","Accidental","ACT","Male",0.370925766539664,2006
"524","All types","ACT","Male",-0.0472340012170824,2006
"525","Accidental","Aus","Male",-0.222153275865403,2006
"526","All types","Aus","Male",0.737928054169502,2006
"527","Accidental","NSW","Male",1.84162109859935,2006
"528","All types","NSW","Male",0.108618171448882,2006
"529","Accidental","NT","Male",0.651647004989177,2006
"530","All types","NT","Male",0.450038806298504,2006
"531","Accidental","Qld","Male",0.720473637088164,2006
"532","All types","Qld","Male",-1.60012084275137,2006
"533","Accidental","SA","Male",-1.58516244953139,2006
"534","All types","SA","Male",0.754576336359223,2006
"535","Accidental","Tas","Male",0.0502221544606974,2006
"536","All types","Tas","Male",0.190143944268155,2006
"537","Accidental","Vic","Male",0.645485865742472,2006
"538","All types","Vic","Male",1.07818890489938,2006
"539","Accidental","WA","Male",0.899680540662523,2006
"540","All types","WA","Male",0.308433071361293,2006

Hi @raytong,

Thanks for flagging that. I have uploaded the csv file in my reply above and modified my code slightly to reflect the change to a csv data file and fewer number of years in the sliderInput.

Cheers,
Nic

Hi @Nic. The problem of your code is not about the conditionalPanel. The problem is you use the same name x and int for two different inputs. So, use unique name for each input will do. And I also add a if statement to subset the plotdata for each choice of input$DropAllB. Hope it can help.

#selectInput selection does not update data/plot when put within conditionalPanel
#

library(shiny)
library(shinythemes)
library(ggplot2)
library(ggthemes)
library(dplyr)
library(plotly)
library(shinycustomloader)
# Define UI for application
ui <- fluidPage(

    # Application title
    titlePanel("selectInput within conditionPanel not updating"),

    # Sidebar with a slider input for number of bins
    sidebarLayout(position = "right",
                  sidebarPanel(
                      sliderInput("yr","Year:",
                                  min = 1997, max = 2006,
                                  value = c(2001,2006), sep = "") ,
                      selectInput("loc", "Jurisdiction",
                                  c("Aus", "ACT", "NSW", "NT",
                                    "Qld", "Tas", "SA", "Vic", "WA"),"Aus") ,
                      radioButtons("DropAllB", "Variable for dropdown list:",
                                   choices = c(
                                       "Type",
                                       "Sex"
                                   ),inline = T,
                                   selected = c("Type")
                      ),

                      #######checkboxGroupInput works, but selectInput does not - selection does not change the data############
                      conditionalPanel(
                          condition = "input.DropAllB == 'Type'",
                          #This doesn't update
                          selectInput("tint", label = NULL,
                                      choices = c("All types",
                                                  "Accidental"),
                                      selected = c("All types") ),
                          #This updates
                          checkboxGroupInput("tx", label = "Sex:",
                                             choices = c("All", "Female", "Male"),
                                             selected = c("All")  )
                      ),

                      conditionalPanel(
                          condition = "input.DropAllB == 'Sex'",
                          #This doesn't update
                          selectInput("sx", label = NULL,
                                      choices = c("All", "Female", "Male"),
                                      selected = c("All") ) ),

                      conditionalPanel(
                          condition = "input.DropAllB == 'Sex'",
                          #This updates
                          checkboxGroupInput(
                              "sint", label = "Type:",
                              c("All types",
                                "Accidental"),
                              selected = c("All types") )
                      )
                      ################### Problem is in this section above ##########################

                      # This works
                      # selectInput("x", "Sex",
                      #     c("All"="All", "Females"="Female", "Males"="Male"),"All") ,
                      # checkboxGroupInput("int", "Type",
                      #  c("Accidental","All types"),"All types")
                  ) ,
                  mainPanel(
                      #Show a plot
                      withLoader(plotlyOutput("test", width = "100%", height = "600px"), type = "html", loader = "loader4")
                  )
    )
)

# Define server logic
server <- function(input, output, session) {
    observe ({
        output$test <- renderPlotly({
            df <- readcsv("test.csv")
            if (input$DropAllB == 'Type') {
                plotdata <- subset(df, subset=(location %in% input$loc &
                                                   sex %in% input$tx & type %in% input$tint))
            } else if (input$DropAllB == 'Sex') {
                plotdata <- subset(df, subset=(location %in% input$loc &
                                                   sex %in% input$sx & type %in% input$sint))
            }

            #     print(input$yr)

            p <- ggplot(plotdata) +
                aes(x = year, y = n, colour=sex, linetype=type, group=1,
                    text = paste0(
                        "Year: ", year,
                        "<br>Number: ", n,
                        "<br>Sex: ", sex,
                        "<br>Location: ", location)) +
                geom_line() +
                scale_color_manual(values = c("All"="black", "Male"="blue", "Female"="red")) +
                scale_linetype_manual(values = c("All types"="solid", "Accidental"="twodash")) +
                xlim(input$yr)

            ggplotly(p, tooltip = "text") %>%
                layout(legend = list(y = 0.95, yanchor = "top"), margin = list(b = 100, l = 100)) %>%
                config(displaylogo=F, modeBarButtonsToRemove = list("sendDataToCloud","zoom2d","pan2d","select2d","lasso2d",
                                                                    "zoomIn2d","zoomOut2d","autoScale2d","hoverClosestCartesian",
                                                                    "hoverCompareCartesian", "resetScale2d", "toggleSpikelines"))
        })
    })
}

# Run the application
shinyApp(ui = ui, server = server)
1 Like

Awesome @raytong thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.