Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.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 tabsetPanel中的多个tabPanel未加载_R_Ggplot2_Shiny - Fatal编程技术网

R tabsetPanel中的多个tabPanel未加载

R tabsetPanel中的多个tabPanel未加载,r,ggplot2,shiny,R,Ggplot2,Shiny,我在ui.R中使用了tabsetPanel,每个tabPanel都有一个特定的绘图。绘图不需要呈现任何用户输入。但仅加载第一个选项卡。当我切换选项卡时,它们是空白的,我必须单击submit按钮才能加载图表。我想在切换选项卡时加载图表。我该怎么做 下面是我的服务器.R代码 服务器.R library(shiny) library(ggplot2) anc_data <- read.csv("anc_indicator.csv", header = TRUE) s

我在ui.R中使用了tabsetPanel,每个tabPanel都有一个特定的绘图。绘图不需要呈现任何用户输入。但仅加载第一个选项卡。当我切换选项卡时,它们是空白的,我必须单击submit按钮才能加载图表。我想在切换选项卡时加载图表。我该怎么做

下面是我的服务器.R代码

服务器.R

   library(shiny)
   library(ggplot2)

   anc_data <- read.csv("anc_indicator.csv", header = TRUE)


   shinyServer(function(input, output) { 

     output$piePlot <- renderPlot({

   # generate pie chart for Totals for the grouping of each indicator
  Totals<-tapply(anc_data$Total,anc_data$Indicator,sum)
  graphdatapie <- as.data.frame(Totals)
  Indicators <-rownames(graphdatapie)
  c <- ggplot(graphdatapie, aes(x=Indicators,y=Totals,fill =   Totals),environment=environment()) + geom_bar(width = 1,stat="identity")
print(c + coord_polar(theta = "y"))
  })
    output$histPlot <- renderPlot({

  # generate histogram for Totals for the grouping of each indicator
  indicatorTotals <- tapply(anc_data$Total,anc_data$Indicator,sum)
  graphdatahist <- as.data.frame(indicatorTotals)
  c <- ggplot(graphdatahist, aes(x=rownames(graphdatahist),y=indicatorTotals,fill =indicatorTotals),environment=environment())
  print(c + geom_bar(width = 1,stat="identity")+ xlab("Indicators")+ylab("ANC Totals"))
   })

  output$boxPlot <- renderPlot({
  # generate box plot for each indicator
  indicatorTotals <- tapply(anc_data$Total,anc_data$Indicator,sum)
  graphdatabox <- as.data.frame(indicatorTotals)
  Indicators <-anc_data$Indicator
  Visits <- anc_data$Total
  c <- ggplot(anc_data, aes(Indicators,Visits),environment=environment())
  print(c + geom_boxplot(outlier.colour = "green", outlier.size = 3,aes(fill = Indicators))+ geom_jitter())
   })

   output$violinPlot <- renderPlot({
 # generate violin plot
 indicatorTotals <- tapply(anc_data$Total,anc_data$Indicator,sum)
 graphdataviolin <- as.data.frame(indicatorTotals)
 Indicators <-anc_data$Indicator
 Visits <- anc_data$Total
 c <- ggplot(anc_data, aes(Indicators,Visits),environment=environment())
print(c + geom_violin(aes(fill = Indicators))+ geom_jitter(height = 0))
  })

 output$timeSeriesPlot <- renderPlot({

 # generate time series graph for each indicator for all periods
 Indicators <-anc_data$Indicator
 c <- ggplot(anc_data, aes(group=factor(anc_data$Indicator),x=anc_data$Period,y=anc_data$Total),environment=environment())
 print(c + geom_line(aes(colour = Indicators),size=2, alpha=0.5)+ xlab("Months") + ylab("ANC Total Visits"))
    })
  })

选项卡和提交按钮之间的奇怪交互是GitHub版本Shinny中修复的一个bug。您可以通过以下步骤进行安装:

install.packages('httpuv', repos=c(RStudio='http://rstudio.org/_packages', CRAN='http://cran.rstudio.com'))
install.packages('devtools')  # if you don't already have devtools installed
devtools::install_github('shiny', 'rstudio')
完成这些步骤后,请确保在重试之前重新启动R进程

install.packages('httpuv', repos=c(RStudio='http://rstudio.org/_packages', CRAN='http://cran.rstudio.com'))
install.packages('devtools')  # if you don't already have devtools installed
devtools::install_github('shiny', 'rstudio')