我正在努力创建一个闪亮的应用程序与互动的选择。如果一个区域已被选中,那么我想过滤我的数据的基础上。但是,如果没有区域已被选中,那么我不想过滤。
我读了一些相关的文章,但似乎没有一个回答我的问题。
下面是我的一些尝试。所有的结果都是一个错误消息
top<-test %>%
filter(date > start_date & date < end_date ) %>%
filter(if (exists(selected_Area))Area==selected_Area else TRUE) %>%
mutate(Quarter=quarter(date, type = "date_first", fiscal_start = 11)) %>%
mutate(Year=year(date))%>%
# getting the top products sold over that timeframe
group_by(Area,Main_Category,Sub_Category,Sample,Analyte,Isolation_Method) %>%
summarise(sum_products_grouped=sum(Products_sold)) %>%
unite(group_name,Sub_Category,Sample,Analyte,Isolation_Method) %>%
top_n(top_numb,sum_products_grouped)
字符串
我也在想这样的事情,但是语法不正确。
if (exists(selected_Area)) {
filter(Area==selected_Area) %>% }
型
数据如下:
> dput(test)
structure(list(PID = c(233L, 233L, 233L, 233L, 233L, 233L, 233L,
233L, 233L, 233L, 233L, 6880L, 6880L, 6880L, 6880L, 6880L, 6880L,
6880L, 6880L, 6880L, 6880L, 6880L, 6880L, 6880L, 6880L, 6880L,
6880L, 6880L, 6880L, 6880L, 6880L, 6880L, 6507L, 6507L, 6507L,
6507L, 6507L, 6507L, 6507L, 6507L, 6507L, 6507L, 6507L, 6507L,
6507L, 6507L, 6507L, 6507L, 6507L, 6507L, 6507L, 6507L, 6507L,
6507L, 6507L, 6507L, 6507L, 6507L, 6507L, 6507L, 6507L, 6507L
), Name = c("Genomic DNA Isolation Kit", "Genomic DNA Isolation Kit",
"Genomic DNA Isolation Kit", "Genomic DNA Isolation Kit", "Genomic DNA Isolation Kit",
"Genomic DNA Isolation Kit", "Genomic DNA Isolation Kit", "Genomic DNA Isolation Kit",
"Genomic DNA Isolation Kit", "Genomic DNA Isolation Kit", "Genomic DNA Isolation Kit",
"FBS Exosome Depletion Kit I (Slurry Format)", "FBS Exosome Depletion Kit I (Slurry Format)",
"FBS Exosome Depletion Kit I (Slurry Format)", "FBS Exosome Depletion Kit I (Slurry Format)",
"FBS Exosome Depletion Kit I (Slurry Format)", "FBS Exosome Depletion Kit I (Slurry Format)",
"FBS Exosome Depletion Kit I (Slurry Format)", "FBS Exosome Depletion Kit I (Slurry Format)",
"FBS Exosome Depletion Kit I (Slurry Format)", "FBS Exosome Depletion Kit I (Slurry Format)",
"FBS Exosome Depletion Kit I (Slurry Format)", "FBS Exosome Depletion Kit I (Slurry Format)",
"FBS Exosome Depletion Kit I (Slurry Format)", "FBS Exosome Depletion Kit I (Slurry Format)",
"FBS Exosome Depletion Kit I (Slurry Format)", "FBS Exosome Depletion Kit I (Slurry Format)",
"FBS Exosome Depletion Kit I (Slurry Format)", "FBS Exosome Depletion Kit I (Slurry Format)",
"FBS Exosome Depletion Kit I (Slurry Format)", "FBS Exosome Depletion Kit I (Slurry Format)",
"FBS Exosome Depletion Kit I (Slurry Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)", "FBS Exosome Depletion Kit I (Column Format)",
"FBS Exosome Depletion Kit I (Column Format)"), Category = c("DNA Kits",
"DNA Kits", "DNA Kits", "DNA Kits", "DNA Kits", "DNA Kits", "DNA Kits",
"DNA Kits", "DNA Kits", "DNA Kits", "DNA Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits", "Multi-Analyte Kits",
"Multi-Analyte Kits", "Multi-Analyte Kits"), Area = c("Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification", "Isolation_and_Purification", "Isolation_and_Purification",
"Isolation_and_Purification"), Main_Category = c("DNA kits",
"DNA kits", "DNA kits", "DNA kits", "DNA kits", "DNA kits", "DNA kits",
"DNA kits", "DNA kits", "DNA kits", "DNA kits", "exosome kits",
"exosome kits", "exosome kits", "exosome kits", "exosome kits",
"exosome kits", "exosome kits", "exosome kits", "exosome kits",
"exosome kits", "exosome kits", "exosome kits", "exosome kits",
"exosome kits", "exosome kits", "exosome kits", "exosome kits",
"exosome kits", "exosome kits", "exosome kits", "exosome kits",
"exosome kits", "exosome kits", "exosome kits", "exosome kits",
"exosome kits", "exosome kits", "exosome kits", "exosome kits",
"exosome kits", "exosome kits", "exosome kits", "exosome kits",
"exosome kits", "exosome kits", "exosome kits", "exosome kits",
"exosome kits", "exosome kits", "exosome kits", "exosome kits",
"exosome kits", "exosome kits", "exosome kits", "exosome kits",
"exosome kits", "exosome kits", "exosome kits", "exosome kits",
"exosome kits", "exosome kits"), Sub_Category = c("DNA Isolation",
"DNA Isolation", "DNA Isolation", "DNA Isolation", "DNA Isolation",
"DNA Isolation", "DNA Isolation", "DNA Isolation", "DNA Isolation",
"DNA Isolation", "DNA Isolation", "Exosome clean-up", "Exosome clean-up",
"Exosome clean-up", "Exosome clean-up", "Exosome clean-up", "Exosome clean-up",
"Exosome clean-up", "Exosome clean-up", "Exosome clean-up", "Exosome clean-up",
"Exosome clean-up", "Exosome clean-up", "Exosome clean-up", "Exosome clean-up",
"Exosome clean-up", "Exosome clean-up", "Exosome clean-up", "Exosome clean-up",
"Exosome clean-up", "Exosome clean-up", "Exosome clean-up", "Exosome clean-up",
"Exosome clean-up", "Exosome clean-up", "Exosome clean-up", "Exosome clean-up",
"Exosome clean-up", "Exosome clean-up", "Exosome clean-up", "Exosome clean-up",
"Exosome clean-up", "Exosome clean-up", "Exosome clean-up", "Exosome clean-up",
"Exosome clean-up", "Exosome clean-up", "Exosome clean-up", "Exosome clean-up",
"Exosome clean-up", "Exosome clean-up", "Exosome clean-up", "Exosome clean-up",
"Exosome clean-up", "Exosome clean-up", "Exosome clean-up", "Exosome clean-up",
"Exosome clean-up", "Exosome clean-up", "Exosome clean-up", "Exosome clean-up",
"Exosome clean-up"), Sample_Category = c("multi-sample", "multi-sample",
"multi-sample", "multi-sample", "multi-sample", "multi-sample",
"multi-sample", "multi-sample", "multi-sample", "multi-sample",
"multi-sample", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", ""), Sample = c("multi-sample", "multi-sample",
"multi-sample", "multi-sample", "multi-sample", "multi-sample",
"multi-sample", "multi-sample", "multi-sample", "multi-sample",
"multi-sample", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS",
"FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS",
"FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS",
"FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS",
"FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS",
"FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS", "FBS"), Analyte = c("totDNA",
"totDNA", "totDNA", "totDNA", "totDNA", "totDNA", "totDNA", "totDNA",
"totDNA", "totDNA", "totDNA", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", ""), Sample_Volume = c("micro",
"micro", "micro", "micro", "micro", "micro", "micro", "micro",
"micro", "micro", "micro", "maxi", "maxi", "maxi", "maxi", "maxi",
"maxi", "maxi", "maxi", "maxi", "maxi", "maxi", "maxi", "maxi",
"maxi", "maxi", "maxi", "maxi", "maxi", "maxi", "maxi", "maxi",
"maxi", "maxi", "maxi", "maxi", "maxi", "maxi", "maxi", "maxi",
"maxi", "maxi", "maxi", "maxi", "maxi", "maxi", "maxi", "maxi",
"maxi", "maxi", "maxi", "maxi", "maxi", "maxi", "maxi", "maxi",
"maxi", "maxi", "maxi", "maxi", "maxi", "maxi"), Isolation_Method = c("spin column",
"spin column", "spin column", "spin column", "spin column", "spin column",
"spin column", "spin column", "spin column", "spin column", "spin column",
"slurry", "slurry", "slurry", "slurry", "slurry", "slurry", "slurry",
"slurry", "slurry", "slurry", "slurry", "slurry", "slurry", "slurry",
"slurry", "slurry", "slurry", "slurry", "slurry", "slurry", "slurry",
"spin column", "spin column", "spin column", "spin column", "spin column",
"spin column", "spin column", "spin column", "spin column", "spin column",
"spin column", "spin column", "spin column", "spin column", "spin column",
"spin column", "spin column", "spin column", "spin column", "spin column",
"spin column", "spin column", "spin column", "spin column", "spin column",
"spin column", "spin column", "spin column", "spin column", "spin column"
), Product_Size = c(100L, 100L, 100L, 100L, 100L, 100L, 100L,
100L, 100L, 100L, 100L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L), date = structure(c(18440,
18470, 18501, 18532, 18562, 18593, 18623, 18654, 18685, 18713,
18744, 19050, 19078, 19109, 19139, 19170, 19200, 19231, 19262,
19292, 19323, 19353, 19384, 19415, 19443, 19474, 19504, 19535,
19565, 19596, 19627, 19657, 17862, 17892, 17923, 17954, 17982,
18013, 18043, 18074, 18104, 18135, 18166, 18196, 18227, 18257,
18288, 18319, 18348, 18379, 18409, 18440, 18470, 18501, 18532,
18562, 18593, 18623, 18654, 18685, 18713, 18744), class = "Date"),
Products_sold = c(3L, 5L, 1L, 2L, 3L, 5L, 2L, 2L, 0L, 0L,
0L, 0L, 2L, 0L, 3L, 0L, 2L, 0L, 0L, 3L, 0L, 1L, 3L, 1L, 1L,
0L, 2L, 0L, 1L, 0L, 0L, 5L, 2L, 0L, 0L, 1L, 2L, 0L, 0L, 0L,
1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L,
0L, 0L, 0L, 0L, 0L, 2L, 0L)), row.names = c(NA, -62L), class = c("tbl_df",
"tbl", "data.frame"))
型
2条答案
按热度按时间kiayqfof1#
考虑到管道,使用下面的命令:
字符串
例如:比较以下内容
型
r8uurelv2#
一种选择是创建一个小的辅助函数
filter_if_selected
。字符串