R Shiny从多个用户输入创建无功(单个)图

时间:2018-04-23 17:31:51

标签: r plot shiny shinydashboard reactive

目标是创建一个用户可以选择的交互式(单一)图 感兴趣的年份,会员的地位和感兴趣的服务 并且每个都将选择正确的数据点。每个x,y坐标都是 分别表示满意度和平均值。我有它合作 只是服务(plot colm),但Id喜欢能够拥有用户 有更多的选择。我对多个输入的尝试是plotOutput(“test”)..

任何想法如何使这段代码工作?谢谢!!

UI:

importance <- c(4.25, 3.08)
satisfaction <- c(3.90, 3.18)
dfGap <- data.frame(importance, satisfaction)

imp.A <- c("3.2","2.5","3.3","4.5","4","3.7")
sat.b <- c("2.2", "3.7","5","1.2","2.6","3")
yr.c <- c("2016","2016","2017","2016", "2016","2017")
status.d <- c("Student", "Not","Student", "Not","Student","Student")
service.e <- c("Huddle", "Web", "Test", "Web","Other","Huddle")

dfTest <- data.frame(imp.A,sat.b,yr.c,status.d, service.e)



colDepend = ("darkred")
range <- c("2016"=1,"2017"=2)
choices <- c("Web" = 1,"Huddle" = 2, "Other" = 3, "Test" = 4)
role <- c("Student" = 1, "Not" = 2)


library(shiny)
library(shinydashboard)
library(ggplot2)


    ui <- dashboardPage(
      dashboardHeader(title="Membership Satisfaction"),
      dashboardSidebar(
        sidebarMenu(
          menuItem("Value Dashboard", tabName = "dashboard", icon = 
    icon("dashboard")),
         menuItem("Services Dashboard", tabName = "service", icon = 
    icon("dashboard")),
        menuItem("Demographics Dashboard", tabName = "demos", icon = 
    icon("dashboard"))
       )
       ),
  dashboardBody(
    tabItems(

      tabItem(tabName = "service",
            sidebarPanel(checkboxGroupInput("vars","Select variables to 
    plot", choices = choices)),
              fluidPage(
                plotOutput("colm"),
                br(),
                br(),
                br(),
                br(),
                br(),
                br(),
                br(),
                br(),
                h6(strong("Gap Analysis: Plot points calculated as mean 
                 importance and mean satisfaction."),
               style = "font-family:'calibri"),
                br(),
                br(),
                h6(strong("Strength: These are the primary strengths. We are 
       meeting highly important services with high satisfaction."),
               style = "font-family:'calibri"),
            h6(strong("Potential Advantages: Member satisfaction is being 
        met, however these services may not be as important for brand 
        equity."),
               style = "font-family:'calibri"),
            h6(strong("Secondary Opportunitites: These services are not 
            crucial (not highly important) and should not be a primary 
            focus."),
               style = "font-family:'calibri"),
            h6(strong("Target Issues: Targeting efforts here can improve 
              membership. These are services that are highly important 
               however are not meeting needs of members."),
               style = "font-family:'calibri")
          )),
      tabItem(tabName = "demos",
          sidebarPanel(
            checkboxGroupInput("inpt","Select variables to plot", choices = 
                 choices),
            checkboxGroupInput("role", 
                               "Select Primary Role of Interest", 
                               choices = role),
            checkboxGroupInput("yrs", 
                               "Select year(S) of Interest", 
                               choices = range)),
          fluidPage(

            plotOutput("test")

          )


      ))

  )
)

服务器:

server <- function(input,output){
  output$matrixValue<- renderTable({
    matrixValue
  },include.rownames=TRUE)

  output$matrixRENEW<- renderTable({
    matrixRENEW
    },include.rownames=TRUE)


  output$value_BP <- renderPlot({
    barplot(matrixValue, beside = T,
          legend.text=rownames(matrixValue),
          args.legend=list(x="topleft"),
          main = titleValue,col=cols)})

  output$renew_BP<- renderPlot({
    barplot(matrixRENEW, beside = T,
          legend.text=rownames(matrixRENEW),
          args.legend=list(x="topleft"),
          main = titleRENEW,col=cols)})


  output$colm <- (renderPlot({
    ggplot(dfGap[input$vars,], aes(satisfaction,importance))+ 
    theme(text=element_text(size=12))+
    geom_point(colour =input$vars, shape = 17, size=5 )+ 
    labs(x = "Mean Satisfaction", y = "Mean Importance") + 
    xlim(0,5) + ylim(0,5)+
    geom_vline(xintercept=2.5) + geom_hline(yintercept =  2.5)+
    annotate("text", x = 4.8, y = 5, 
           label = "Strengths", 
           color = "chartreuse4",
           style = "font-family:'calibri", 
           size =6.5,
           fontface =2)+
   annotate("text", x = .3, y = 5, 
           label = "Target Issues", 
           color = "firebrick4",
           style = "font-family:'calibri", 
           size =6.5,
           fontface =2)+
   annotate("text", x = .78, y = 0, 
           label = "Secondary Opportunities", 
           color = "dodgerblue3",
           style = "font-family:'calibri", 
           size =6.5,
           fontface =2)+
   annotate("text", x = 4.4, y = 0, 
           label = "Potential Advantages", 
           color = "grey10",
           style = "font-family:'calibri", 
           size =6.5,
           fontface =2)

  }))






  output$test <- renderPlot({

   ggplot(dfTest[service.e[service.e==input$inpt,],], aes(imp.A,sat.b))+ 
    theme(text=element_text(size=12))+
    geom_point(colour ="green", shape = 17, size=5 )+ 
    labs(x = "Mean Satisfaction", y = "Mean Importance") + 
    xlim(0,5) + ylim(0,5)+
    geom_vline(xintercept=2.5) + geom_hline(yintercept =  2.5)+
    annotate("text", x = 4.8, y = 5, 
           label = "Strengths", 
           color = "chartreuse4",
           style = "font-family:'calibri", 
           size =6.5,
           fontface =2)+
    annotate("text", x = .3, y = 5, 
           label = "Target Issues", 
           color = "firebrick4",
           style = "font-family:'calibri", 
           size =6.5,
           fontface =2)+
    annotate("text", x = .78, y = 0, 
           label = "Secondary Opportunities", 
           color = "dodgerblue3",
           style = "font-family:'calibri", 
           size =6.5,
           fontface =2)+
    annotate("text", x = 4.4, y = 0, 
           label = "Potential Advantages", 
           color = "grey10",
           style = "font-family:'calibri", 
           size =6.5,
           fontface =2)})


}



shinyApp (ui = ui, server = server)

服务选项卡正在运行我希望演示选项卡如何工作,我只是努力获取不同的用户输入以类似的方式映射到绘图。任何帮助是极大的赞赏!!

0 个答案:

没有答案