Skip to content

Commit 0c7a727

Browse files
committed
updated gridstack to 11.3.0
1 parent 6cc1628 commit 0c7a727

File tree

11 files changed

+209
-6633
lines changed

11 files changed

+209
-6633
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: gridstackr
22
Title: Interactive grid layout with the JavaScript 'GridStack' Library
3-
Version: 0.0.0.9200
3+
Version: 0.0.0.9300
44
Authors@R: c(
55
person("Victor", "Perrier", email = "[email protected]", role = c("aut", "cre")),
66
person("Fanny", "Meyer", role = "aut"))
@@ -9,7 +9,7 @@ Description: Create movable and resizable grid layout in 'Shiny' application.
99
License: MIT + file LICENSE
1010
Encoding: UTF-8
1111
Roxygen: list(markdown = TRUE)
12-
RoxygenNote: 7.3.1
12+
RoxygenNote: 7.3.2
1313
Imports:
1414
htmltools,
1515
htmlwidgets,

R/proxy.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ gs_proxy_add <- function(proxy, item, options = list()) {
8181
.gs_proxy(
8282
proxy = proxy,
8383
name = "add-widget",
84-
l = list(options = options)
84+
l = list(options = options, id = paste0("grid-stack-item-content-", ID))
8585
)
8686
if (inherits(item, "ggplot")) {
8787
gg_fun <- exprToFunction(item, parent.frame(), FALSE)

examples/filter-grid.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ card_pkg <- function(.list) {
2020
tags$div(.list$Description)
2121
),
2222
fill = FALSE,
23-
height = "100%"
23+
height = "100%",
24+
class = "mb-0"
2425
)
2526
}
2627

2728
item_pkg <- function(pkg) {
28-
gs_item(card_pkg(pkg), w = 3, id = pkg$Package)
29+
gs_item(card_pkg(pkg), w = 3, id = pkg$Package, sizeToContent = TRUE)
2930
}
3031
item_pkg_all <- function(pkgs) {
3132
lapply(

examples/shiny-two-2.R

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
library(shiny)
3+
library(bslib)
4+
library(ggplot2)
5+
library(gridstackr)
6+
7+
ui <- page_fluid(
8+
tags$h2("Two GridStack example"),
9+
fluidRow(
10+
column(
11+
width = 3,
12+
tags$b("List of charts to put in dashboard:"),
13+
# gridstackOutput("grid1")
14+
gridstack(
15+
column = 1,
16+
minRow = 1,
17+
cellHeight = "210px",
18+
options = list(
19+
acceptWidgets = TRUE,
20+
dragOut = TRUE
21+
),
22+
elementId = "grid1"
23+
)
24+
),
25+
column(
26+
width = 9,
27+
tags$b("Dashboard:"),
28+
gridstackOutput("grid2")
29+
)
30+
)
31+
)
32+
33+
server <- function(input, output, session) {
34+
35+
plot_list <- list(
36+
ggplot(mtcars) + geom_point(aes(mpg, disp)) + ggtitle("Plot 1"),
37+
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear)) + ggtitle("Plot 2"),
38+
ggplot(mtcars) + geom_smooth(aes(disp, qsec)) + ggtitle("Plot 3"),
39+
ggplot(mtcars) + geom_bar(aes(carb)) + ggtitle("Plot 4"),
40+
ggplot(mtcars) + geom_point(aes(hp, wt, colour = mpg)) + ggtitle("Plot 5")
41+
)
42+
43+
# output$grid1 <- renderGridstack({
44+
# gridstack(
45+
# column = 4,
46+
# minRow = 1,
47+
# cellHeight = "210px",
48+
# options = list(
49+
# acceptWidgets = TRUE,
50+
# dragOut = TRUE
51+
# )#,
52+
# # list_items = lapply(
53+
# # X = seq_along(plot_list),
54+
# # FUN = function(i) {
55+
# # gs_item(
56+
# # h = 2,
57+
# # id = paste0("plot_", i),
58+
# # renderPlot({
59+
# # plot_list[[i]]
60+
# # }, height = "100%", width = "100%")
61+
# # )
62+
# # }
63+
# # )
64+
# )
65+
# })
66+
67+
observe({
68+
lapply(
69+
X = seq_along(plot_list),
70+
FUN = function(i) {
71+
gs_proxy_add("grid1", plot_list[[i]], list(id = paste0("plot_", i), w = 4, h = 2))
72+
}
73+
)
74+
})
75+
76+
output$grid2 <- renderGridstack({
77+
gridstack(
78+
minRow = 3,
79+
# cellHeight = "210px",
80+
options = list(
81+
acceptWidgets = TRUE,
82+
dragOut = TRUE
83+
)
84+
)
85+
})
86+
87+
}
88+
89+
if (interactive())
90+
shinyApp(ui, server)

examples/shiny-two.R

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,48 @@ server <- function(input, output, session) {
2626
gridstack(
2727
margin = "10px",
2828
cellHeight = "140px",
29-
column = 1,
29+
column = 3,
3030
options = list(
3131
acceptWidgets = TRUE,
3232
dragOut = TRUE
3333
),
34-
gs_item(value_box(
35-
title = "Customer lifetime value",
36-
value = "$5,000",
37-
showcase = icon("bank"),
38-
theme = "text-success",
39-
class = "mb-0"
40-
)),
41-
gs_item(value_box(
42-
title = "Customer lifetime value",
43-
value = "$5,000",
44-
showcase = icon("bank"),
45-
theme = value_box_theme(bg = "#e6f2fd", fg = "#0B538E"),
46-
class = "border mb-0"
47-
)),
4834
gs_item(
35+
w = 3,
36+
value_box(
37+
title = "Customer lifetime value",
38+
value = "$5,000",
39+
showcase = icon("bank"),
40+
theme = "text-success",
41+
class = "mb-0"
42+
)
43+
),
44+
gs_item(
45+
w = 3,
46+
value_box(
47+
title = "Customer lifetime value",
48+
value = "$5,000",
49+
showcase = icon("bank"),
50+
theme = value_box_theme(bg = "#e6f2fd", fg = "#0B538E"),
51+
class = "border mb-0"
52+
)
53+
),
54+
gs_item(
55+
w = 3,
4956
plotOutput("plot1", height = "100%"),
5057
class_content = "bg-white p-2 border rounded-4"
5158
),
5259
gs_item(
60+
w = 3,
5361
plotOutput("plot2", height = "100%"),
5462
class_content = "bg-white p-2 border rounded-4"
5563
),
5664
gs_item(
65+
w = 3,
5766
plotOutput("plot3", height = "100%"),
5867
class_content = "bg-white p-2 border rounded-4"
5968
),
6069
gs_item(
70+
w = 3,
6171
plotOutput("plot4", height = "100%"),
6272
class_content = "bg-white p-2 border rounded-4"
6373
)
@@ -67,6 +77,7 @@ server <- function(input, output, session) {
6777
output$grid2 <- renderGridstack({
6878
gridstack(
6979
minRow = 3,
80+
column = 6,
7081
cellHeight = "140px",
7182
options = list(
7283
acceptWidgets = TRUE,
@@ -78,7 +89,6 @@ server <- function(input, output, session) {
7889
output$plot1 <- renderPlot({
7990
ggplot(mtcars) + geom_point(aes(mpg, disp))
8091
})
81-
outputOptions(output, "plot1", suspendWhenHidden = TRUE)
8292
output$plot2 <- renderPlot({
8393
ggplot(mtcars) + geom_boxplot(aes(gear, disp, group = gear))
8494
})

examples/shiny-widgets.R

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
library(shiny)
2+
library(bslib)
3+
library(ggplot2)
4+
library(gridstackr)
5+
library(sortable)
6+
7+
ui <- page_fillable(
8+
tags$h2("GridStack example"),
9+
layout_sidebar(
10+
sidebar = sidebar(
11+
width = 300,
12+
gridstackOutput("bucket")
13+
),
14+
gs_trash(id = "mytrash", label = "Drag here to remove", height = "50px"),
15+
gridstackOutput("dashboard")
16+
)
17+
)
18+
19+
server <- function(input, output, session) {
20+
21+
output$bucket <- renderGridstack({
22+
gridstack(
23+
disableResize = TRUE,
24+
column = 1,
25+
options = list(
26+
acceptWidgets = TRUE,
27+
dragOut = TRUE
28+
),
29+
gs_item(
30+
selectInput(
31+
inputId = "variable",
32+
label = "Variable:",
33+
choices = c(
34+
"Cylinders" = "cyl",
35+
"Transmission" = "am",
36+
"Gears" = "gear"
37+
)
38+
),
39+
tableOutput("data")
40+
))
41+
})
42+
43+
output$dashboard <- renderGridstack({
44+
gridstack(
45+
margin = "10px",
46+
cellHeight = "140px",
47+
resize_handles = "all",
48+
float = TRUE,
49+
options = list(
50+
acceptWidgets = TRUE
51+
),
52+
trash_id = "mytrash"
53+
)
54+
})
55+
56+
observeEvent(input$dashboard_layout, {
57+
print(input$dashboard_layout)
58+
})
59+
60+
output$data <- renderTable({
61+
mtcars[, c("mpg", input$variable), drop = FALSE]
62+
}, rownames = TRUE)
63+
64+
}
65+
66+
if (interactive())
67+
shinyApp(ui, server)

0 commit comments

Comments
 (0)