работает следующий код (без ввода цвета / фигуры), однако попытка сделать точки разными фигурами / цветами оказалась сложной, я не уверен, в чем проблема.
Я пытаюсь получить:
год / диапазон имеют желтый контур вокруг формы
Продукт должен быть разных форм
Статус / Роль разных цветов
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")
# tableOutput("test")
)))))
Мой сервер:
server <- function(input,output){
library(tidyverse)
xPre <- reactive({
inpt <- as.double(input$inpt)
role <- as.double(input$role)
range <- as.double(input$range)
GapAnalysis_LongFormB %>%
filter(Product %in% inpt,
year %in% range)
})
yPre <- reactive({
inpt <- as.double(input$inpt)+1
role <- as.double(input$role)
range <- as.double(input$range)
GapAnalysis_LongFormB %>%
filter(Product %in% inpt,
year %in% range)
})
xPost<- reactive({
xPre<- xPre()
inpt <- as.double(input$inpt)
role <- as.double(input$role)
range <- as.double(input$range)
xPre %>%
filter(year %in% range,
Product %in% inpt,
status %in% role)%>%
group_by(Product, status,year)%>%
summarize(avg = mean(Score, na.rm = TRUE)) %>%
pull(-1)
})
yPost<- reactive({
yPre <- yPre()
inpt <- as.double(input$inpt)+1
role <- as.double(input$role)
range <- as.double(input$range)
yPre %>%
filter(year %in% range,
Product %in% inpt,
status %in% role)%>%
group_by(Product, status,year)%>%
summarize(avg = mean(Score, na.rm = TRUE)) %>%
pull(-1)
})
ySum <- reactive({
yPre <- yPre()
inpt <- as.double(input$inpt)+1
role <- as.double(input$role)
range <- as.double(input$range)
yPre %>%
filter(year %in% range,
Product %in% inpt)%>%
group_by(Product,year)%>%
summarize(avg = mean(Score, na.rm = TRUE)) %>%
pull(-1)
})
xSum <- reactive({
xPre <- xPre()
inpt <- as.double(input$inpt)
role <- as.double(input$role)
range <- as.double(input$range)
xPre %>%
filter(year %in% range,
Product %in% inpt)%>%
group_by(Product,year)%>%
summarize(avg = mean(Score, na.rm = TRUE)) %>%
pull(-1)
})
xyCoords<- reactive({
xPost <- xPost()
yPost <- yPost()
xSum <- xSum()
ySum <- ySum()
as.data.frame(matrix(c(xPost,xSum,yPost,ySum),ncol = 2))
})
output$test<- renderTable({
xyCoords <- xyCoords()
})
output$plot <- renderPlot({
xyCoords <- xyCoords()
xyCoords %>%
ggplot(aes(x=V1, y =V2 )) +
geom_point(colour = "blue", 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)
структура переменной для 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")
когда я пытаюсь выполнить color = input $ inpt или shape = input $ inpt, я получаю сообщение об ошибке «Эстетика должна иметь длину 1 или совпадать с данными (3): shape, color, size»
Есть идеи? СПАСИБО !!