我正在尝试设置一个仪表板,用户可以通过年份、状态和产品筛选数据。理想情况下,每个产品都有两个相关的变量,满意度得分和重要性得分。从数据集中过滤时,应计算各个感兴趣的部分的摘要均值。然后,平均重要性和平均满意度得分合并到数据帧中,并绘制在单个图中。
以下是我的进展...
我的用户界面。
以下是变量结构:
它可以工作 - 但没有完全满足我的需求。目前,在绘图之前,它需要在所有三个复选框输入变量(inpt,role,range)中输入内容。我需要它要求一个产品,但对于每个额外的输入都进行绘制。这意味着,如果他们选择Web,则会绘制Web的平均值。如果他们选择Web和2017年,则会绘制2017年Web的平均值。非常感谢您的帮助!
以下是我的进展...
我的用户界面。
library(shiny)
library(dplyr)
library(shinydashboard)
library(tidyverse)
ui <- dashboardPage(
dashboardHeader(title="Membership Satisfaction"),
dashboardSidebar(
sidebarMenu(
menuItem("Demographics Dashboard", tabName = "demos", icon =
icon("dashboard"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "demos",
sidebarPanel(
checkboxGroupInput("inpt","Select variables to plot",
choices =
c("Web" = 1,"Huddle" = 3, "Other" = 5,
"Test" = 7)),
checkboxGroupInput("role",
"Select Primary Role of Interest",
choices = c("Student" = 1, "Not" = 2)),
checkboxGroupInput("range",
"Select year(S) of Interest",
choices = c("2016"=2,"July 2017"=1))),
fluidPage(
plotOutput("plot")
)))))
我的服务器:
server <- function(input,output){
library(tidyverse)
x <- reactive({
inpt <- as.double(input$inpt)
role <- as.double(input$role)
range <- as.double(input$range)
GapAnalysis_LongFormB %>%
filter(Product %in% inpt,
status %in% role,
year %in% range) %>%
summarize(avg = mean(Score, na.rm = TRUE)) %>%
pull(-1)
})
y <- reactive({
inpt <- as.double(input$inpt)+1
role <- as.double(input$role)
range <- as.double(input$range)
GapAnalysis_LongFormB %>%
filter(Product %in% inpt,
status %in% role,
year %in% range) %>%
summarize(avg = mean(Score, na.rm = TRUE))%>%
pull(-1)
})
xyCoords<- reactive({
x <- x()
y <- y()
data.frame(col1=x, col2=y)
})
output$plot <- renderPlot({
xyCoords <- xyCoords()
xyCoords %>%
ggplot(aes(x = col1, y = col2)) +
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)
})
}
shinyApp (ui = ui, server = server)
以下是变量结构:
> dput(head(GapAnalysis_LongFormB))
structure(list(status = c(1, 5, 5, 1, 1, 5), year = c(1, 1, 1,
1, 1, 1), Product = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("1",
"2", "3", "4"), class = "factor"), Score = c(2, 5, 3, 5, 4, 4
)), .Names = c("status", "year", "Product", "Score"), row.names = c(NA,
6L), class = "data.frame")
它可以工作 - 但没有完全满足我的需求。目前,在绘图之前,它需要在所有三个复选框输入变量(inpt,role,range)中输入内容。我需要它要求一个产品,但对于每个额外的输入都进行绘制。这意味着,如果他们选择Web,则会绘制Web的平均值。如果他们选择Web和2017年,则会绘制2017年Web的平均值。非常感谢您的帮助!
as.integer(input$inpt+1)
。这不应该是as.integer(input$inpt) + 1
吗? - akrun