remove columns with a condition

I have a problem with my shiny code, I want to make a conditional that tells me the na of each column of a dataframe and that shows me the columns that meet the condition that the na are greater than 30 percent of the total rows

ui <- dashboardPage(
  dashboardHeader(title = titulo, titleWidth = 250, disable= F
  ),#header
  
  dashboardSidebar(width = 250, disable = F,
                   fluidPage( 
                     sidebarMenu( 
                       
                       menuItem("Carga",tabName = "carga", icon = icon("upload")),
                       menuItem("Selección",tabName = "selec")
                                
                     )#sidebarMenu
                   )# fluidPage     
  ), #dashboardSidebar

  dashboardBody(
    fluidPage(
      tabItems(
        
       
        tabItem(tabName = "carga",
                           tabPanel(strong("Ingreso"),
                                    h3("Carga de Datos"),
                                    tags$hr(),
                                    fluidRow(
                                      column(5,
                                             selectInput("separador",
                                                         h4("Separador"),
                                                         choices = list(" , " = ",",
                                                                        " ; " = ";",
                                                                        "Seleccione una opción"= 3
                                                         ),
                                                         selected = 3
                                             ),
                                             # tags$hr(),
                                             checkboxInput("header", "Encabezado", TRUE),
                                             selectInput("codificar",
                                                         h4("Elegir codificación"),
                                                         choices = list("Seleccione una opción"= 3, 
                                                                        " ISO-8859-1 " = "ISO-8859-1",
                                                                        " UTF-8 " = "UTF-8",
                                                                        " ASCII " = "ASCII",
                                                                        "  BIG5" = "BIG5",
                                                                        " GB18030 " = "GB18030",
                                                                        " GB2312 " = "GB2312",
                                                                        " ISO-2022-JP " = "ISO-2022-JP",
                                                                        " ISO-2022-KR " = "ISO-2022-KR",
                                                                        " ISO-8859-2 " = "ISO-8859-2",
                                                                        " ISO-8859-7 " = "ISO-8859-7",
                                                                        " SHIFT-JIS " = "SHIFT-JIS",
                                                                        " WINDOWS-1252 " = "WINDOWS-1252"
                                                         ),
                                                         selected = 3
                                             )
                                      ),#column
                                      column(5,
                                             fileInput("fichero",
                                                       h4("Archivo"),
                                                       buttonLabel = "Fichero",
                                                       placeholder = "selecciona un fichero",
                                                       accept = c(
                                                         "text/csv",
                                                         "text/comma-separated-values,text/plain",
                                                         ".csv"
                                                       ),
                                                       multiple = F)
                                      )#column
                                    )#fluidrown
                           ) #tabpanel ingreso
            
        ),#carga
        
        tabItem(tabName = "selec",
               
                           tabPanel(strong("Tabla"),
                                    sidebarLayout(
                                      sidebarPanel(
                                        uiOutput("uiSeleccion"),
        
                                      ),
                                      mainPanel(
                                        br(),
                                        box( height = "500",width = "15",solidHeader = T,
                                             dataTableOutput("tabla1"),style = "height:500px; overflow-y: scroll;overflow-x: scroll;"
                                        )#BOX
                                      )#mainPanel
                                    )#sidebarLayout
                           )#tabpanel seleccion
                           
               
        )#tabItem seleccion
      )#tabItems
    )#fluidpage
  )#dashboardBody
)#dashboardPage

the problem is spelled out in the render output $ uiSelection <- renderUI ({

server <- function(input, output, session) {
  
  ####-------------RENDER DE FILEINPUT CARGA ---------------------
  
  archivo1 <- reactive({
    file <- input$fichero
    if (is.null(file)|| input$separador == 3)
      return(NULL)
    archivo <- read.csv(file$datapath, 
                        sep = input$separador,
                        header = input$header,
                        encoding = input$codificar,
                        na = c("", "NA"),
                        stringsAsFactors = F
    )
    
  })
  

  ####------------ RENDER DE SELECCION-----------------------------------
  ####------------ render seleccion checkbox
#####------------
#####------------
#####------------
#####------------
#####------------ In this UI render it shows all the columns.
#What we want is that first make the condition of the total NA per column be> 30% and show these #columns in the checkboxGroupInput to select them

  output$uiSeleccion <- renderUI({
   
    checkboxGroupInput("variables", "Columnas del dataset para  mostrar:",
                       names(archivo1()), selected = names(archivo1()))
 
  })
  
  ####------------ render archivo de seleccion
  
  archivo2 <- reactive({
    archivo1()[ ,input$variables, drop = F 
                ]})
  
  ####------------ render tabla de seleccion
  
  output$tabla1 <- renderDataTable({
    
    DT::datatable(archivo2())
  })
}

Is this some sort of assignment for a course? If it is, the polite thing to do would be to make it clear.
As I said before to other user with almost the same question, this issue is not specific to shiny, it would be better if you isolate the relevant part and try to solve it outside shiny first.
Take a look at the other thread for an example

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