Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Shiny - How to filter variables in table and boxplot using checkboxGroupInput

I don't know how to code server to filter variables choice using checkboxGroupInput. I want to filter variables that will be show in boxplot as well as in table. I added all variables in UI.

My code: (I use multi-multi.csv dataset)

UI

shinyUI(fluidPage(
  sidebarLayout(
    sidebarPanel(
      fileInput("fileInPath", label= h4("Import danych")),
      sliderInput("kolor", h4("Wybierz kolor"),min = 0, max = 1, value = 0.5, step=0.05),
      checkboxGroupInput("kolumna", h4("Wybierz kolumny"), choices = c('L1', 'L2', 'L3', 'L4', 'L5', 'L6', 'L7', 'L8', 'L9', 'L10', 'L11', 'L12', 'L13','L14', 'L15', 'L16', 'L17', 'L18', 'L19', 'L20')),
      mainPanel(
      tabsetPanel(type = "tabs",
                  tabPanel("Table", tableOutput("daneIn")),
                  tabPanel("Plot", plotOutput("plot")),
                  tabPanel("Model", verbatimTextOutput("model"))))) ))

SERVER

library(shiny)
library(ggplot2)
library(reshape)

model <- function(d){
  tmpTab <- table(as.integer(unlist((d[,-c(1:4)]))))
  ret <- as.integer(head(names(tmpTab[order(tmpTab,decreasing=T)]),10))
  ret <- as.data.frame(matrix(ret,ncol=1))
  return(ret)
}
shinyServer(function(input, output) {
  dataIn <- reactive({
    inFile <- input$fileInPath
    if (is.null(inFile)) {
      return(NULL)
    } read.table(file=inFile$datapath,sep=";",dec=",",header=T,stringsAsFactors=FALSE)
  })
  output$daneIn <- renderTable({
    ret <- rbind(
      head(dataIn(),5),
      tail(dataIn(),5)
    )
    return(ret)
  },include.rownames=FALSE)
  output$plot <- renderPlot({
    d <- dataIn()
    InColor <- rgb(as.numeric(input$kolor),0,0,1)
    d <- melt(d[,-c(2:4)],id.vars="Numer")
    wyk <- (
      ggplot(d,aes(x=variable,y=value)) 
      + geom_boxplot(color = InColor) 
      + xlab("") + ylab("Kula")
    ) 
    return(wyk)
  }) 
  output$model <- renderPrint({
    d <- dataIn()
    ret <- model(d)
    return(ret)
  }) 
  })

Comments