在Shiny R应用程序的下拉列表中模拟自动选择

时间:2017-03-01 19:31:19

标签: r shiny populate

我有一个应用程序,根据下拉列表中的选择,我正在生成一个情节。我想知道我是否可以自动进行选择,以便程序在点击按钮时查看所有值并根据输入绘制图表。 这是相同的代码。

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)))
    } )

  }

)

如果能在Shiny中实现,请告诉我。基本上我试图为文件中的所有行生成一个运行图。单击按钮可以触发操作。

谢谢, TEJ

0 个答案:

没有答案