Max and min in a sliderinput that changes according to the column that I choose

Viewed 53

I need that a sliderInput ajust to max and min, acordl an specific row that I choose. I have a database like this:

     Indicea<-c(1,2,3,5,3,1,3,5,3,6,2,1,1,3,2)
     Indiceb<-c(12,15,12,14,13,16,14,13,15,12,14,13,15,11,12)
     Indicec<-c(100,120,154,125,201,102,150,102,105,140,156,118,113,175,189)
     Indiced<-c(0.1,0.5,06,032,0.1,0.25,0.23,0.12,0.15,
     0.25,0.45,1.0,0.5,0.26,0.45,0.89)
     Especialidad<-c("gato","gato","gato","perro","perro","perro","perro",
     "buho","buho","buho","buho","tigre","tigre","tigre","tigre")
      data<-dataframe(Indicea, Indiceb,Indicec,Indiced,Especialidad)

This is how looks my UI,I have four different indexes, I need be able to pick any and that the sliderInput fits

    tabItem("IndicesI",
   tabsetPanel(position= "left",
    tabPanel("Indices de ingreso", icon = icon("file-medical-alt"),
             sidebarLayout(sidebarPanel(
                uiOutput("SeleccioneIndice"),
               uiOutput("Rango"),
                uiOutput("SeleccioneEspecialidad2"),
                checkboxInput("Todas","Seleccione Todas/Ninguna", value = FALSE)
             ),
             mainPanel(
                plotOutput("lineplotI"),
                dataTableOutput("summary9")
             )))

And like this is how looks my server

   output$SeleccioneEspecialidad2<-renderUI({
   selectInput("SeleccioneEspecialidad2", "Seleccione Especialidad",
        data$Especialidad, multiple = T, selected = TRUE )
     })
   BD<-reactive({
   data %>%
   filter(Especialidad %in% input$SeleccioneEspecialidad2 )
    }) 
   output$SeleccioneIndice <-renderUI({
   selectInput("SeleccioneIndice", "Seleccione Indice", choices= 
    c("Ments"="Indicea", "Fragilidad"="Indiceb",                                                         
   "ElixhauserAHRQ"="Indicec",                                                          
    "ElixhauserVanWalraven"="Indiced"))

    })
     output$Rango<-renderUI({  
     sliderInput("Rango",label = "Seleccione un rango", min = 0, 
     })
     })
1 Answers

EDIT: Including some NAs in the indices. Perhaps you can try this

Indicea<-c(1,2,3,5,3,1,3,5,3,6,NA,2,1,1,3,2)
Indiceb<-c(12,15,12,14,13,16,14,13,15,12,14,13,NA,13,11,12)
Indicec<-c(100,NA,120,154,125,201,102,150,102,105,140,156,118,113,175,189)
Indiced<-c(0.1,0.5,06,032,0.1,0.25,0.23,0.12,0.15,NA,
           0.25,0.45,1.0,0.5,0.26,0.45)
Especialidad<-c("gato","gato","gato","perro","perro","perro","perro",
                "buho","buho","buho","buho","tigre","tigre","tigre",NA,"tigre")
data <- data.frame(Indicea, Indiceb,Indicec,Indiced,Especialidad)

ui <- fluidPage(
  tabItem("IndicesI",
          tabsetPanel(# position= "left",
                      tabPanel("Indices de ingreso", icon = icon("file-medical-alt"),
                               sidebarLayout(sidebarPanel(
                                 uiOutput("SeleccioneEspecialidad2"),
                                 uiOutput("SeleccioneIndice"),
                                 uiOutput("Rango"),
                                 checkboxInput("Todas","Seleccione Todas/Ninguna", value = FALSE)
                               ),
                               mainPanel(
                                 plotOutput("lineplotI"),
                                 dataTableOutput("summary9")
                               )))
          )
  )
)

server <- function(input, output, session) {
  output$SeleccioneEspecialidad2<-renderUI({
    choices <- na.omit(data$Especialidad)
    selectInput("SeleccioneEspecialidad2", "Seleccione Especialidad",
                choices=choices, multiple = T, selected = TRUE )
  })

  BD<-reactive({
    req(input$SeleccioneEspecialidad2)
    data %>%
      filter(Especialidad %in% input$SeleccioneEspecialidad2 )
  })

  output$SeleccioneIndice <-renderUI({
    selectInput("SeleccioneIndice", "Seleccione Indice", choices=
                  c("Ments"="Indicea",
                    "Fragilidad"="Indiceb",
                    "ElixhauserAHRQ"="Indicec",
                    "ElixhauserVanWalraven"="Indiced"))

  })

  output$Rango<-renderUI({
    req(input$SeleccioneIndice)
    minn <- min(BD()[,input$SeleccioneIndice], na.rm = TRUE)
    maxx <- max(BD()[,input$SeleccioneIndice], na.rm = TRUE)
    valu <- minn + (maxx - minn)/2
    sliderInput("Rango",label = "Seleccione un rango", min = minn, max=maxx, value=valu)
  })

}

shinyApp(ui, server)
Related