vendredi 24 novembre 2017

Checkbox doesn't work when I use several renderUi on Shiny

I used a checkbox in my Shiny app that didn't work (couldn't update).

I tried to reach the root of the problem, and found that it appeared when I wrote the second "renderUi" function in my code (output$secondSelectionVarIllu, the 2nd function in the server) : when I delete it, the checkbox works.

Does anyone know why ?

What is the problem in my code ?

PS : I use renderUi because if I write the sliderInput in the ui, I don't achieve to include "input$choix_var" in the parameters. If there is another solution for that, it could also delete the problem, even if I'd like to understand this matter of checkbox !

PS2 : it isn't a problem of data, the only thing that doesn't work is the TRUE/FALSE option of the checkbox

Thank you very much !

# Define UI ----
ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(

      selectInput(inputId = "choix_var",label="Variables utilisées pour la construction des axes :",
                  choices=as.list(noms_var),multiple=T),

      uiOutput("secondSelectionNbAxes"),
      uiOutput("secondSelectionVarIllu"),

      checkboxInput(inputId = "aff_histo_vp","Affichage de l'histogramme des valeurs propres",TRUE)
   ),

    mainPanel(
        conditionalPanel(condition = "input.aff_histo_vp",
             plotOutput("histo_vp")            
        )
    )
  )
)


# Define server ----
server <- function(input, output) {

  output$secondSelectionNbAxes <- renderUI({
    sliderInput(inputId = "nb_axes",label="Choix du nombre de composantes principales :",
                min=2,max=length(input$choix_var),value=2,step=1)
  })

  output$secondSelectionVarIllu <- renderUI({
    conditionalPanel(condition="length(input$choix_var) < nb_var",
                     selectInput(inputId = "choix_var_illu",label="Variables illustratives :",
                                 choices=names(data_acp_cr)[which(!names(data_acp_cr) %in% names(data_acp_cr[,which(names(data_acp_cr) %in% input$choix_var)]))],multiple=T))
  }) 

  output$histo_vp <- renderPlot({
     acp <- dudi.pca(data_acp_cr[,which(names(data_acp_cr) %in% input$choix_var)],scannf = F,nf=input$nb_axes) 
    fviz_eig(acp,main="Histogramme des valeurs propres") 
  })
}




Aucun commentaire:

Enregistrer un commentaire