|
| 1 | +library(jsTreeR) |
| 2 | +library(shiny) |
| 3 | + |
| 4 | +nodes <- list( |
| 5 | + list( |
| 6 | + text = "Fruits", |
| 7 | + type = "fruit", |
| 8 | + icon = "supertinyicon-transparent-raspberry_pi", |
| 9 | + a_attr = list(class = "helvetica"), |
| 10 | + children = list( |
| 11 | + list( |
| 12 | + text = "Apple", |
| 13 | + type = "fruit", |
| 14 | + data = list( |
| 15 | + price = 0.1, |
| 16 | + quantity = 20, |
| 17 | + cssclass = "lightorange" |
| 18 | + ) |
| 19 | + ), |
| 20 | + list( |
| 21 | + text = "Banana", |
| 22 | + type = "fruit", |
| 23 | + data = list( |
| 24 | + price = 0.2, |
| 25 | + quantity = 31, |
| 26 | + cssclass = "lightorange" |
| 27 | + ) |
| 28 | + ), |
| 29 | + list( |
| 30 | + text = "Grapes", |
| 31 | + type = "fruit", |
| 32 | + data = list( |
| 33 | + price = 1.99, |
| 34 | + quantity = 34, |
| 35 | + cssclass = "lightorange" |
| 36 | + ) |
| 37 | + ), |
| 38 | + list( |
| 39 | + text = "Mango", |
| 40 | + type = "fruit", |
| 41 | + data = list( |
| 42 | + price = 0.5, |
| 43 | + quantity = 8, |
| 44 | + cssclass = "lightorange" |
| 45 | + ) |
| 46 | + ), |
| 47 | + list( |
| 48 | + text = "Melon", |
| 49 | + type = "fruit", |
| 50 | + data = list( |
| 51 | + price = 0.8, |
| 52 | + quantity = 4, |
| 53 | + cssclass = "lightorange" |
| 54 | + ) |
| 55 | + ), |
| 56 | + list( |
| 57 | + text = "Pear", |
| 58 | + type = "fruit", |
| 59 | + data = list( |
| 60 | + price = 0.1, |
| 61 | + quantity = 30, |
| 62 | + cssclass = "lightorange" |
| 63 | + ) |
| 64 | + ), |
| 65 | + list( |
| 66 | + text = "Strawberry", |
| 67 | + type = "fruit", |
| 68 | + data = list( |
| 69 | + price = 0.15, |
| 70 | + quantity = 32, |
| 71 | + cssclass = "lightorange" |
| 72 | + ) |
| 73 | + ) |
| 74 | + ), |
| 75 | + state = list( |
| 76 | + opened = TRUE |
| 77 | + ) |
| 78 | + ), |
| 79 | + list( |
| 80 | + text = "Vegetables", |
| 81 | + type = "vegetable", |
| 82 | + icon = "supertinyicon-transparent-vegetarian", |
| 83 | + a_attr = list(class = "helvetica"), |
| 84 | + children = list( |
| 85 | + list( |
| 86 | + text = "Aubergine", |
| 87 | + type = "vegetable", |
| 88 | + data = list( |
| 89 | + price = 0.5, |
| 90 | + quantity = 8, |
| 91 | + cssclass = "lightgreen" |
| 92 | + ) |
| 93 | + ), |
| 94 | + list( |
| 95 | + text = "Broccoli", |
| 96 | + type = "vegetable", |
| 97 | + data = list( |
| 98 | + price = 0.4, |
| 99 | + quantity = 22, |
| 100 | + cssclass = "lightgreen" |
| 101 | + ) |
| 102 | + ), |
| 103 | + list( |
| 104 | + text = "Carrot", |
| 105 | + type = "vegetable", |
| 106 | + data = list( |
| 107 | + price = 0.1, |
| 108 | + quantity = 32, |
| 109 | + cssclass = "lightgreen" |
| 110 | + ) |
| 111 | + ), |
| 112 | + list( |
| 113 | + text = "Cauliflower", |
| 114 | + type = "vegetable", |
| 115 | + data = list( |
| 116 | + price = 0.45, |
| 117 | + quantity = 18, |
| 118 | + cssclass = "lightgreen" |
| 119 | + ) |
| 120 | + ), |
| 121 | + list( |
| 122 | + text = "Potato", |
| 123 | + type = "vegetable", |
| 124 | + data = list( |
| 125 | + price = 0.2, |
| 126 | + quantity = 38, |
| 127 | + cssclass = "lightgreen" |
| 128 | + ) |
| 129 | + ) |
| 130 | + ) |
| 131 | + ) |
| 132 | +) |
| 133 | + |
| 134 | +grid <- list( |
| 135 | + columns = list( |
| 136 | + list( |
| 137 | + width = 200, |
| 138 | + header = "Product", |
| 139 | + headerClass = "bolditalic yellow centered", |
| 140 | + wideValueClass = "cssclass" |
| 141 | + ), |
| 142 | + list( |
| 143 | + width = 150, |
| 144 | + value = "price", |
| 145 | + header = "Price", |
| 146 | + wideValueClass = "cssclass", |
| 147 | + headerClass = "bolditalic yellow centered", |
| 148 | + wideCellClass = "centered" |
| 149 | + ), |
| 150 | + list( |
| 151 | + width = 150, |
| 152 | + value = "quantity", |
| 153 | + header = "Quantity", |
| 154 | + wideValueClass = "cssclass", |
| 155 | + headerClass = "bolditalic yellow centered", |
| 156 | + wideCellClass = "centered" |
| 157 | + ) |
| 158 | + ), |
| 159 | + width = 600 |
| 160 | +) |
| 161 | + |
| 162 | +types <- list( |
| 163 | + fruit = list( |
| 164 | + a_attr = list( |
| 165 | + class = "lightorange" |
| 166 | + ), |
| 167 | + icon = "supertinyicon-transparent-symantec" |
| 168 | + ), |
| 169 | + vegetable = list( |
| 170 | + a_attr = list( |
| 171 | + class = "lightgreen" |
| 172 | + ), |
| 173 | + icon = "supertinyicon-transparent-symantec" |
| 174 | + ) |
| 175 | +) |
| 176 | + |
| 177 | +ui <- fluidPage( |
| 178 | + tags$head( |
| 179 | + tags$style( |
| 180 | + HTML(c( |
| 181 | + ".lightorange {background-color: #fed8b1;}", |
| 182 | + ".lightgreen {background-color: #98ff98;}", |
| 183 | + ".bolditalic {font-weight: bold; font-style: italic; font-size: large;}", |
| 184 | + ".yellow {background-color: yellow !important;}", |
| 185 | + ".centered {text-align: center; font-family: cursive;}", |
| 186 | + ".helvetica {font-weight: 700; font-family: Helvetica; font-size: larger;}" |
| 187 | + )) |
| 188 | + ) |
| 189 | + ), |
| 190 | + titlePanel("jsTree grid"), |
| 191 | + jstreeOutput("ajstree") |
| 192 | +) |
| 193 | + |
| 194 | +server <- function(input, output){ |
| 195 | + output[["ajstree"]] <- |
| 196 | + renderJstree(jstree(nodes, search = TRUE, grid = grid, types = types)) |
| 197 | +} |
| 198 | + |
| 199 | +shinyApp(ui, server) |
0 commit comments