复选框组合选择闪亮R

时间:2016-05-04 20:25:08

标签: r shiny shiny-server

我正在尝试使用闪亮的复选框来选择不同的视图。复选框的每个组合都有一个单独的视图(带有不同数据帧的qplot视图)。我的服务器代码变得复杂,我想知道是否,因为我是新手,我错过了一个更简单的方法。此外,当我选择所有三个选项时,正确的视图不会显示 - 当我输入2个选项时,它可以正常工作。

这是我的UI.R代码:

hr(),
h5(textOutput("Select Followers & Unfollowers View")),
checkboxInput("check_followers", label = h6("Followers"), value = FALSE),
checkboxInput("check_unfollowers", label = h6("Unfollowers"), value = FALSE),
checkboxInput("check_diff", label = h6("Followers minus unfollowers"), value = FALSE),

这是我的服务器.R代码:

  if (input$check_followers == TRUE) { 
    if(input$check_unfollowers == TRUE){
      if (input$check_diff == TRUE) {

      ## plot for all 3  cumulative
        plot_SaleTrends <-  qplot(month, count, data= cumsum_foll_unfoll_diff_merge, color=type,  xlab="month", ylab="Count", geom ="line")

        # if checkbox to add trend line to plot
        if (input$trendlineselect == TRUE) {
          plot_SaleTrends <- plot_SaleTrends + 
            geom_smooth(method=loess, span=input$trendline_sen_sel, level=as.numeric(input$trendline_conf_sel))
        }
      }


        ## plot for follower and unfollow cumulative
        plot_SaleTrends <- qplot(month, count, data= foll_unfoll_cumsub, color=type,  xlab="month", ylab="Count", geom ="line")
        # if checkbox to add trend line to plot
        if (input$trendlineselect == TRUE) {
          plot_SaleTrends <- plot_SaleTrends + 
            geom_smooth(method=loess, span=input$trendline_sen_sel, level=as.numeric(input$trendline_conf_sel))

      }}

     else if (input$check_diff == TRUE){
        ## plot follower and diff cumulative 
       plot_SaleTrends <- qplot(month, count, data= diff_foll_cumsub, color=type,  xlab="month", ylab="Count", geom ="line")
       # if checkbox to add trend line to plot
       if (input$trendlineselect == TRUE) {
         plot_SaleTrends <- plot_SaleTrends + 
           geom_smooth(method=loess, span=input$trendline_sen_sel, level=as.numeric(input$trendline_conf_sel))
       }
     }
        ## plot just for follower cumulative 
         plot_SaleTrends <-  qplot(month, count, data= foll_cumsub, color=type,  xlab="month", ylab="Count", geom ="line")
        # if checkbox to add trend line to plot
         if (input$trendlineselect == TRUE) {
              plot_SaleTrends <- plot_SaleTrends + 
         geom_smooth(method=loess, span=input$trendline_sen_sel, level=as.numeric(input$trendline_conf_sel))


      }

  }



 if (input$check_unfollowers == TRUE) { # unfollower
   if (input$check_followers == TRUE) { 
     if (input$check_diff == TRUE) {
       ## plot all 3
       plot_SaleTrends <-  qplot(month, count, data= cumsum_foll_unfoll_diff_merge, color=type,  xlab="month", ylab="Count", geom ="line")

       # if checkbox to add trend line to plot
       if (input$trendlineselect == TRUE) {
         plot_SaleTrends <- plot_SaleTrends + 
           geom_smooth(method=loess, span=input$trendline_sen_sel, level=as.numeric(input$trendline_conf_sel))
       }

     }
     # plot follower and unfollower
     plot_SaleTrends <- qplot(month, count, data= foll_unfoll_cumsub, color=type,  xlab="month", ylab="Count", geom ="line")
     # if checkbox to add trend line to plot
     if (input$trendlineselect == TRUE) {
       plot_SaleTrends <- plot_SaleTrends + 
         geom_smooth(method=loess, span=input$trendline_sen_sel, level=as.numeric(input$trendline_conf_sel))
     }
   }
  else if (input$check_diff == TRUE){
       #plot unfollow and diff
    plot_SaleTrends <-  qplot(month, count, data= diff_unfoll_cumsub, color=type,  xlab="month", ylab="Count", geom ="line")
    # if checkbox to add trend line to plot
    if (input$trendlineselect == TRUE) {
      plot_SaleTrends <- plot_SaleTrends + 
        geom_smooth(method=loess, span=input$trendline_sen_sel, level=as.numeric(input$trendline_conf_sel))
    }
  }
   else{
     #plot unfollow only
     plot_SaleTrends <- qplot(month, count, data= unfoll_cumsub, color=type,  xlab="month", ylab="Count", geom ="line")
     # if checkbox to add trend line to plot
     if (input$trendlineselect == TRUE) {
       plot_SaleTrends <- plot_SaleTrends + 
         geom_smooth(method=loess, span=input$trendline_sen_sel, level=as.numeric(input$trendline_conf_sel))
     }

   }
   } 

任何帮助将不胜感激

0 个答案:

没有答案