Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在应用程序中的下拉列表中模拟自动选择_R_Shiny_Populate - Fatal编程技术网

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

R 在应用程序中的下拉列表中模拟自动选择,r,shiny,populate,R,Shiny,Populate,我有一个应用程序,根据下拉列表中的选择,我生成一个绘图。我想知道我是否可以使选择自动进行,这样,程序点击一个按钮就会遍历所有值,并根据输入绘制图表。 下面是相同的代码 用户界面 #ui.R 图书馆(闪亮) ds我不知道您为什么需要选择Input?因为您不想从这个输入中选择一个特定的值,而是全部使用它们。还有一个问题:假设您的选择input中有n个值,那么您是否希望将n个图作为所需的输出,并在彼此下方绘制?是否希望通过单击按钮更新相同的图? # ui.R library(shiny) ds

我有一个应用程序,根据下拉列表中的选择,我生成一个绘图。我想知道我是否可以使选择自动进行,这样,程序点击一个按钮就会遍历所有值,并根据输入绘制图表。 下面是相同的代码

用户界面


#ui.R
图书馆(闪亮)

ds我不知道您为什么需要
选择Input
?因为您不想从这个输入中选择一个特定的值,而是全部使用它们。还有一个问题:假设您的
选择input
中有n个值,那么您是否希望将n个图作为所需的输出,并在彼此下方绘制?是否希望通过单击按钮更新相同的图?
# 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
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)))
    } )

  }

)