TD <- thyroid
library(readxl)
library(shiny)
library(ggplot2)
library(shinythemes)
library(DT)
ui <-shinyUI(fluidPage(pageWithSidebar(
  headerPanel("Test App"),
  sidebarPanel(
    selectInput("xaxis", "Choose a x variable", choices = names(TD)),
    selectInput("T4", "T4 Rate", choices = c("All","0 - 80","80 - 140","> 140")),
    selectInput("T3", "T4 Rate", choices = c("All","0 - 80","80 - 140","> 140")),
    selectInput("TSH", "T4 Rate", choices = c("All","0 - 80","80 - 140","> 140")),
    
    actionButton("goButton","Update")
  ),
  mainPanel(
    tabsetPanel(
      tabPanel('Plot1', plotOutput("plot1")),
      tabPanel('Plot2', plotOutput("plot2"))
    ))
)
))
server <- shinyServer(function(input,output, session){
  
  data1 <- reactive({
    if(input$T4 == "All"){
      TD
    }
    else if(input$T4 == "0 - 80"){
      TD[which(TD$T4 >= 0 & TD$T4 < 80),]
        
    }
    else if(input$T4 == "80 - 140"){
      TD[which(TD$T4 >= 80 & TD$T4 < 140),]
      
    }
    else{
      TD[which(TD$T4 >= 140),]
    
      
        
    }
  })
  x_var<- eventReactive(input$goButton, {
    input$xaxis
  })
  
  output$plot1 <- renderPlot({
    x <- x_var()
    
    p <- ggplot() + geom_bar(aes(x=TD[[x]], fill = TD$ThryroidClass))
    p  #+ 
      #theme(plot.title = element_text(hjust = 0.5, size=20))
  })
  output$plot2 <- renderPlot({
    x <- x_var()
    
    p <- ggplot() + geom_bar(aes(x=data1[[x]], fill = TD$ThryroidClass))
    p  #+ 
      #theme(plot.title = element_text(hjust = 0.5, size=20))
  })
})
shinyApp(ui,server)
I m working on the thyroid dataset i wanna compare groups of patients which are probably sick from thyroid based on the T4 rate. THis is why i have created a subset of my original according to that rate. i have done 2 plos, the one with the whole dataset works perfectly, but the second with the sub set five me the followinf error : Error[object object] How can i handle this please??
