我正在为我的数据创建一个闪亮的应用程序,但是我的当前代码并没有显示情节。另外,根据第8列,我还想将我的数据分类到两个复选框"Stage1“和"Stage2”下。基于下拉列表,数据范围和复选框显示子集/过滤数据并显示图表。Stage1<-(mytest$status_2019|mytest$status_2020|mytest$status_2021|mytest$status_2022==1) Stage2<-(mytest$status_stage2_2019|mytest$status_stage2_2020|mytest$status_stage2_2021|mytest$status_stage2_2022==1)
这是我的数据:
mydata<-structure(list(Id = c("DB-1", "DB-2", "DB-3", "DB-4", "DB-5",
"DB-6", "DB-7", "DB-9", "DB-11", "DB-12", "DB-13", "DB-14", "DB-15",
"DB-16", "DB-17", "DB-18", "DB-19", "DB-20", "DB-23", "DB-25",
"DB-26", "DB-27", "DB-28", "DB-29", "DB-30", "DB-31", "DB-32",
"DB-34", "DB-35", "DB-36", "DB-37"), examiner = c("Alex", "Alex",
"Alex", "Alex", "Alex", "Alex", "Kim", "Kim", "Kim", "Kim", "Kim",
"Alex", "Alex", "Jhon", "Jhon", "Jhon", "Jhon", "Jhon", "Jhon",
"Maymoon", "Maymoon", "Maymoon", "Maymoon", "Maymoon", "Mike",
"Mike", "Mike", "Mike", "Mike", "Mike", "Mike"), Relationship = c("sibling",
"mother", "self", "father", "self", "self", "self", "self", "self",
"mother", "self", "self", "self", "self", "mother", "father",
"self", "self", "mother", "self", "self", "self", "self", "sibling",
"father", "mother", "mother", "mother", "mother", "self", "father"
), signed_date = c("12/4/18", "11/27/18", "11/30/18", "11/13/18",
"11/27/18", "11/13/18", "11/28/18", "2/26/19", "4/3/19", "1/15/19",
"4/3/19", "11/13/18", "2/25/19", "12/6/18", "1/15/19", "11/30/18",
"12/4/18", "11/20/18", "4/3/19", "2/25/19", "2/14/19", "12/6/18",
"3/14/19", "12/7/18", "1/10/19", "3/12/19", "3/22/19", "12/20/18",
"3/21/19", "4/5/19", "11/15/18"), gender = c("male", "female",
"male", "male", "male", "male", "female", "female", "female",
"female", "male", "female", "female", "female", "female", "male",
"male", "female", "female", "female", "male", "male", "female",
"male", "male", "female", "female", "female", "female", "female",
"male"), stage1_date = c("2/21/19 21:15", "1/10/19 21:45", "1/9/19 19:50",
"1/10/19 21:40", "1/10/19 21:45", "1/9/20 14:50", "1/10/19 21:45",
"3/15/19 16:50", "4/26/19 19:20", "3/21/19 18:21", "4/26/19 19:20",
"1/10/19 21:40", "3/15/19 16:50", "1/10/19 21:45", "3/21/19 18:21",
"1/31/19 20:25", NA, "1/10/19 21:45", "1/9/20 14:50", "7/30/19 15:10",
"3/4/19 16:30", NA, "4/8/19 12:40", "2/6/19 20:36", "1/31/19 20:25",
"5/1/19 18:05", "4/8/19 12:41", "1/17/19 19:26", "5/1/19 18:05",
NA, "1/10/19 21:45"), stage2_date = c(NA, NA, NA, NA, "5/11/21 17:50",
NA, "5/21/21 17:46", NA, "5/11/21 17:37", NA, "5/21/21 17:47",
"5/15/21 16:07", "5/16/21 16:07", NA, NA, NA, "5/11/21 17:52",
NA, NA, "5/14/21 16:07", "5/11/21 17:37", "5/11/21 17:52", NA,
NA, NA, NA, NA, NA, NA, "5/11/21 17:42", NA), status_2019 = c(1,
1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1, 0, 1), status_2020 = c(0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0), status_2021 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
status_2022 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), status_stage2_2020 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), status_stage2_2021 = c(0,
0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0), status_stage2_2022 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), row.names = c(NA, -31L
), spec = structure(list(cols = list(Id = structure(list(), class = c("collector_character",
"collector")), Onboarded = structure(list(), class = c("collector_character",
"collector")), Relationship = structure(list(), class = c("collector_character",
"collector")), signed_date = structure(list(), class = c("collector_character",
"collector")), gender = structure(list(), class = c("collector_character",
"collector")), stage1_date = structure(list(), class = c("collector_character",
"collector")), stage2_date = structure(list(), class = c("collector_character",
"collector")), status_2019 = structure(list(), class = c("collector_double",
"collector")), status_2020 = structure(list(), class = c("collector_double",
"collector")), status_2021 = structure(list(), class = c("collector_double",
"collector")), status_2022 = structure(list(), class = c("collector_double",
"collector")), status_stage2_2020 = structure(list(), class = c("collector_double",
"collector")), status_stage2_2021 = structure(list(), class = c("collector_double",
"collector")), status_stage2_2022 = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = ","), class = "col_spec"), problems = <pointer: 0x7f7f0a7dc7c0>, class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"))这是我的代码:
library(shiny)
library(tidyverse)
library(dplyr)
library(ggplot2)
library(lubridate)
mydata <- read_csv("test.csv")
mydata$signed_date <- as.Date(mydata$signed_date, format = "%Y-%m-%d", optional=FALSE)
server <- function(input, output, session) {
#Summarize Data and then Plot
data <- reactive({
req(input$examiner)
mydata %>%
dplyr::filter(examiner %in% input$examiner ,
signed_date >= input$daterange[1] &
signed_date <= input$daterange[2]) %>%
group_by(relation) %>% summarize(Total = n())
})
output$selected_var <- renderText({
paste("You have chosen ", input$examiner, "between", input$Dates[1], "and", input$Dates[2])
})
#Plot
output$plot <- renderPlot({
g <- ggplot(data(), aes( y = Total, x = relation))
g + geom_bar(stat = "sum")
})
}
ui <- basicPage(
titlePanel("My Dashboard"),
helpText("Shows my data"),
selectInput(inputId = "examiner",
label = h3("Choose examiner"),
choices = c("None", as.character(mydata$examiner), selected = "None")),
dateRangeInput("Dates", h3("Select the Dates"), format="yyyy-mm-dd", start = "2018-04-01"),
mainPanel(
textOutput("selected_var"),
plotOutput("plot")
)
)
shinyApp(ui = ui, server = server)现在,我在filter()输入..1中遇到以下错误问题。[34m ..1 [39m输入ℹ为examiner %in% input$examiner ]。[31 39m]找不到39米物体“考官”
发布于 2022-04-27 02:37:26
你有多个问题:
我已经开始清理其中的一些排字,但我会让你去弄清楚日期问题。下面的browser()语句包含在其中一个反应器中。运行该应用程序,然后在R控制台上交互地查看日期问题(通过运行类似于class(mydata$stage1_date)的程序)。一旦你清理了日期问题,发布更好的数据。
这是比较近一点的东西。
mydata <-
structure(
list(
Id = c(
"DB-1",
"DB-2",
"DB-3",
"DB-4",
"DB-5",
"DB-6",
"DB-7",
"DB-9",
"DB-11",
"DB-12",
"DB-13",
"DB-14",
"DB-15",
"DB-16",
"DB-17",
"DB-18",
"DB-19",
"DB-20",
"DB-23",
"DB-25",
"DB-26",
"DB-27",
"DB-28",
"DB-29",
"DB-30",
"DB-31",
"DB-32",
"DB-34",
"DB-35",
"DB-36",
"DB-37"
),
examiner = c(
"Alex",
"Alex",
"Alex",
"Alex",
"Alex",
"Alex",
"Kim",
"Kim",
"Kim",
"Kim",
"Kim",
"Alex",
"Alex",
"Jhon",
"Jhon",
"Jhon",
"Jhon",
"Jhon",
"Jhon",
"Maymoon",
"Maymoon",
"Maymoon",
"Maymoon",
"Maymoon",
"Mike",
"Mike",
"Mike",
"Mike",
"Mike",
"Mike",
"Mike"
),
Relationship = c(
"sibling",
"mother",
"self",
"father",
"self",
"self",
"self",
"self",
"self",
"mother",
"self",
"self",
"self",
"self",
"mother",
"father",
"self",
"self",
"mother",
"self",
"self",
"self",
"self",
"sibling",
"father",
"mother",
"mother",
"mother",
"mother",
"self",
"father"
),
application_date = c(
"12/4/18",
"11/27/18",
"11/30/18",
"11/13/18",
"11/27/18",
"11/13/18",
"11/28/18",
"2/26/19",
"4/3/19",
"1/15/19",
"4/3/19",
"11/13/18",
"2/25/19",
"12/6/18",
"1/15/19",
"11/30/18",
"12/4/18",
"11/20/18",
"4/3/19",
"2/25/19",
"2/14/19",
"12/6/18",
"3/14/19",
"12/7/18",
"1/10/19",
"3/12/19",
"3/22/19",
"12/20/18",
"3/21/19",
"4/5/19",
"11/15/18"
),
gender = c(
"male",
"female",
"male",
"male",
"male",
"male",
"female",
"female",
"female",
"female",
"male",
"female",
"female",
"female",
"female",
"male",
"male",
"female",
"female",
"female",
"male",
"male",
"female",
"male",
"male",
"female",
"female",
"female",
"female",
"female",
"male"
),
stage1_date = c(
"2/21/19 21:15",
"1/10/19 21:45",
"1/9/19 19:50",
"1/10/19 21:40",
"1/10/19 21:45",
"1/9/20 14:50",
"1/10/19 21:45",
"3/15/19 16:50",
"4/26/19 19:20",
"3/21/19 18:21",
"4/26/19 19:20",
"1/10/19 21:40",
"3/15/19 16:50",
"1/10/19 21:45",
"3/21/19 18:21",
"1/31/19 20:25",
NA,
"1/10/19 21:45",
"1/9/20 14:50",
"7/30/19 15:10",
"3/4/19 16:30",
NA,
"4/8/19 12:40",
"2/6/19 20:36",
"1/31/19 20:25",
"5/1/19 18:05",
"4/8/19 12:41",
"1/17/19 19:26",
"5/1/19 18:05",
NA,
"1/10/19 21:45"
),
stage2_date = c(
NA,
NA,
NA,
NA,
"5/11/21 17:50",
NA,
"5/21/21 17:46",
NA,
"5/11/21 17:37",
NA,
"5/21/21 17:47",
"5/15/21 16:07",
"5/16/21 16:07",
NA,
NA,
NA,
"5/11/21 17:52",
NA,
NA,
"5/14/21 16:07",
"5/11/21 17:37",
"5/11/21 17:52",
NA,
NA,
NA,
NA,
NA,
NA,
NA,
"5/11/21 17:42",
NA
),
status_2019 = c(
1,
1,
1,
1,
1,
0,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
1,
0,
1,
1,
0,
1,
1,
1,
1,
1,
1,
1,
0,
1
),
status_2020 = c(
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
),
status_2021 = c(
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
),
status_2022 = c(
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
),
status_stage2_2020 = c(
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
),
status_stage2_2021 = c(
0,
0,
0,
0,
1,
0,
1,
0,
1,
0,
1,
1,
1,
0,
0,
0,
1,
0,
0,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
1,
0
),
status_stage2_2022 = c(
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
)
),
row.names = c(NA, -31L),
spec = structure(list(
cols = list(
Id = structure(list(), class = c("collector_character",
"collector")),
Onboarded = structure(list(), class = c("collector_character",
"collector")),
Relationship = structure(list(), class = c("collector_character",
"collector")),
application_date = structure(list(), class = c("collector_character",
"collector")),
gender = structure(list(), class = c("collector_character",
"collector")),
stage1_date = structure(list(), class = c("collector_character",
"collector")),
stage2_date = structure(list(), class = c("collector_character",
"collector")),
status_2019 = structure(list(), class = c("collector_double",
"collector")),
status_2020 = structure(list(), class = c("collector_double",
"collector")),
status_2021 = structure(list(), class = c("collector_double",
"collector")),
status_2022 = structure(list(), class = c("collector_double",
"collector")),
status_stage2_2020 = structure(list(), class = c("collector_double",
"collector")),
status_stage2_2021 = structure(list(), class = c("collector_double",
"collector")),
status_stage2_2022 = structure(list(), class = c("collector_double",
"collector"))
),
default = structure(list(), class = c("collector_guess",
"collector")),
delim = ","
), class = "col_spec"),
# problems = < pointer:0x7f7f0a7dc7c0 > ,
class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame")
)
library(shiny)
library(tidyverse)
library(dplyr)
library(ggplot2)
library(lubridate)
# mydata <- read_csv("test.csv")
mydata$signed_date <-
as.Date(mydata$signed_date, format = "%Y-%m-%d", optional = FALSE)
server <- function(input, output, session) {
#Summarize Data and then Plot
data <- reactive({
req(input$examiner)
browser()
mydata %>%
dplyr::filter(
examiner %in% input$examiner ,
stage1_date >= input$daterange[1] &
stage1_date <= input$daterange[2]
) %>%
group_by(Relationship) %>% summarize(Total = n())
})
output$selected_var <- renderText({
paste("You have chosen ",
input$examiner,
"between",
input$Dates[1],
"and",
input$Dates[2])
})
#Plot
output$plot <- renderPlot({
g <- ggplot(data(), aes(y = Total, x = relation))
g + geom_bar(stat = "sum")
})
}
ui <- basicPage(
titlePanel("My Dashboard"),
helpText("Shows my data"),
selectInput(
inputId = "examiner",
label = h3("Choose examiner"),
choices = c("None", as.character(mydata$examiner), selected = "None")
),
dateRangeInput(
"daterange",
h3("Select the Dates"),
format = "yyyy-mm-dd",
start = "2018-04-01"
),
mainPanel(textOutput("selected_var"),
plotOutput("plot"))
)
shinyApp(ui = ui, server = server)发布于 2022-04-27 16:08:34
正如@dca所指出的,您的代码输入太多了。尝尝这个
mydata$signed_date <- as.Date(mydata$application_date, format = "%m/%d/%y", optional=FALSE)
server <- function(input, output, session) {
#Summarize Data and then Plot
data <- reactive({
#req(input$examiner)
if (is.null(input$examiner) | input$examiner=="None") return(NULL)
mydata %>% dplyr::filter(examiner %in% input$examiner) %>%
dplyr::filter(signed_date >= input$Dates[1] & signed_date <= input$Dates[2]) %>%
group_by(Relationship) %>% dplyr::summarize(Total = n())
})
output$selected_var <- renderText({
paste("You have chosen ", input$examiner, "between", input$Dates[1], "and", input$Dates[2])
})
#Plot
output$plot <- renderPlot({
req(data())
g <- ggplot(data(), aes( y = Total, x = Relationship))
g + geom_bar(stat = "sum")
})
}
ui <- basicPage(
titlePanel("My Dashboard"),
helpText("Shows my data"),
selectInput(inputId = "examiner",
label = h3("Choose examiner"),
choices = c("None", unique(mydata$examiner)), selected = "None"),
dateRangeInput("Dates", h3("Select the Dates"), format="yyyy-mm-dd", start = "2018-04-01"),
mainPanel(
textOutput("selected_var"),
plotOutput("plot")
)
)
shinyApp(ui = ui, server = server)https://stackoverflow.com/questions/72022071
复制相似问题