Simulate auto selection in a drop down in Shiny R application

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Simulate auto selection in a drop down in Shiny R application

tej246
I have an application where based on the selection in a drop down, I am generating a plot. I want to know if I can make the selection auto so that, the program goes through all the values on click of a button and plots a chart based on the input. Here is the code for the same.

ui.R

ui.R

library(shiny)

ds <- read.csv(file="data/InPatient_Disease_Year_AgeGroup_Count_Shinycsv.csv",header = TRUE, sep = ",") unq= unique(ds$CCS_DIAGNOSIS_DESCRIPTION,incomparables = FALSE)

shinyUI(fluidPage( titlePanel("Inpatient data by disease"),

sidebarLayout( sidebarPanel( helpText("Select a disease."),

  selectInput("val",
              label = "Choose a disease",
              choices =unq,
              selected  ="ABDOMINAL HERNIA"
              )
  ),

mainPanel(plotOutput("map"))
) ))

Sys.sleep(3)

server.R

server.R

library(shiny)

ds <- read.csv(file="data/InPatient_Disease_Year_AgeGroup_Count_Shinycsv.csv",header = TRUE, sep = ",")

shinyServer( function(input, output){

output$map <- renderPlot({

  val=input$val

  if (is.null(val))
    return(NULL)
  age_grp <- c("0 to 17", "18 to 29", "30 to 49", "50 to 69", "70 or Older")
  colours <- c("red", "orange", "blue", "yellow", "green")
  #unq= unique(ds$CCS_DIAGNOSIS_DESCRIPTION,incomparables = FALSE)




    df= ds[ds$CCS_DIAGNOSIS_DESCRIPTION == val ,c("Year_Age_Y","Number.Of.Cases")]

    #barplot(df$`Number.Of.Cases`,names.arg = df$Year_Age_Y,ylab=val, col=colours,beside=TRUE,legend = age_grp)
    barplot(df$`Number.Of.Cases`,main=val,names.arg = df$Year_Age_Y, las=2,space=0.5,mar=c(9.1, 5.1, 5.1, 1.1),col=colours,beside=TRUE,font.axis=1,ps=2,legend = age_grp,args.legend = list(x = "topleft", bty = "n",cex=0.6, inset=c(-0.05, -0.10)))
} )
}

)

Please let me know if this can be achieved in Shiny. Basically I trying to generate a running plot form a file for all the rows in the file. The action can be triggered by clicking on a button.

Thanks, Tej