|
| 1 | +options_picker_taxo <- shinyWidgets::pickerOptions( |
| 2 | + actionsBox = TRUE, |
| 3 | + selectedTextFormat = "count > 3", |
| 4 | + liveSearch = TRUE, |
| 5 | + noneSelectedText = "All", |
| 6 | + showTick = TRUE, |
| 7 | + size = 5 |
| 8 | +) |
| 9 | + |
| 10 | +options_picker_taxo_kingdom <- shinyWidgets::pickerOptions( |
| 11 | + actionsBox = TRUE, |
| 12 | + selectedTextFormat = "count > 3", |
| 13 | + liveSearch = TRUE, |
| 14 | + noneSelectedText = "None", |
| 15 | + showTick = TRUE, |
| 16 | + size = 5 |
| 17 | +) |
| 18 | + |
| 19 | +# ================================= |
| 20 | + |
| 21 | +# Small function to return the taxo level number |
| 22 | +# |
| 23 | +# @param taxo_level character |
| 24 | +# |
| 25 | +# @return the taxo_level number |
| 26 | +# |
| 27 | +# @noRd |
| 28 | +# |
| 29 | +# @examples taxo_level_number("genus") |
| 30 | +# # [1] 7 |
| 31 | +# |
| 32 | +# |
| 33 | +taxo_level_number <- function(taxo_level) { |
| 34 | + which(global$taxo_levels == taxo_level) |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +# |
| 39 | +# ================================= |
| 40 | + |
| 41 | +# Small function to return the taxo level and taxon name |
| 42 | +# |
| 43 | +# @param kingdom |
| 44 | +# @param supergroup |
| 45 | +# @param division |
| 46 | +# @param class |
| 47 | +# @param order |
| 48 | +# @param family |
| 49 | +# @param genus |
| 50 | +# @param species |
| 51 | +# |
| 52 | +# @return A named vector with 3 elements. The first level which is not NULL, the corresponding name or names and the taxo as a list |
| 53 | +# |
| 54 | +# @noRd |
| 55 | +# # |
| 56 | +# @examples |
| 57 | +# |
| 58 | +# taxo_return("Eukaryota","S", "D", "C", "O", c("F", "F1"), NULL, NULL) |
| 59 | +# # $level |
| 60 | +# # [1] "family" |
| 61 | +# # |
| 62 | +# # $name |
| 63 | +# # [1] "F" "F1" |
| 64 | +# # |
| 65 | +# # $kingdom |
| 66 | +# # [1] "Eukaryota" |
| 67 | +# # |
| 68 | +# # $supergroup |
| 69 | +# # [1] "S" |
| 70 | +# # |
| 71 | +# # $division |
| 72 | +# # [1] "D" |
| 73 | +# # |
| 74 | +# # $class |
| 75 | +# # [1] "C" |
| 76 | +# # |
| 77 | +# # $order |
| 78 | +# # [1] "O" |
| 79 | +# # |
| 80 | +# # $family |
| 81 | +# # [1] "F" "F1" |
| 82 | +# # |
| 83 | +# # $genus |
| 84 | +# # NULL |
| 85 | +# # |
| 86 | +# # $species |
| 87 | +# # NULL |
| 88 | + |
| 89 | + |
| 90 | +taxo_return <- function(kingdom, supergroup, division, class, order, family, genus, species) { |
| 91 | + |
| 92 | + |
| 93 | + taxo_1 <- c(kingdom[1], supergroup[1], division[1], class[1], order[1], family[1], genus[1], species[1]) |
| 94 | + taxo_list <- list(kingdom = kingdom, supergroup = supergroup, division=division, |
| 95 | + class=class, order = order, family = family, genus = genus, species = species) |
| 96 | + |
| 97 | + # The levels for which nothing is selected return NULL and the length of the vector gives the first rank which is NULL |
| 98 | + |
| 99 | + if (length(taxo_1) == 0) { |
| 100 | + return( c(level = "kingdom", list(name = unique(global$kingdom)), taxo_list)) |
| 101 | + } |
| 102 | + |
| 103 | + |
| 104 | + taxo_level <- global$taxo_levels[length(taxo_1)] |
| 105 | + message("Taxo level: ", taxo_level) |
| 106 | + |
| 107 | + |
| 108 | + # Then the name(s) are just extracted from the list for the taxo_level |
| 109 | + |
| 110 | + taxo_name <- taxo_list[[taxo_level]] |
| 111 | + |
| 112 | + message("Taxo name: ", taxo_name) |
| 113 | + |
| 114 | + # Very strange, the if one puts the name in the list then if there are more than one it is returned as several names (name1, name2 etc...) |
| 115 | + # See: https://stackoverflow.com/questions/9031819/add-named-vector-to-a-list |
| 116 | + |
| 117 | + return( c(level = taxo_level, list(name = taxo_name), taxo_list)) |
| 118 | +} |
| 119 | + |
0 commit comments