Skip to content

Commit eac7185

Browse files
committed
Use page_navbar() for shared sidebar
1 parent dca0e3c commit eac7185

File tree

1 file changed

+68
-26
lines changed
  • inst/apps/312-bslib-sidebar-resize

1 file changed

+68
-26
lines changed
Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
### Keep this line to manually test this shiny application. Do not edit this line; shinycoreci::::is_manual_app
2-
31
library(shiny)
42
library(bslib)
53
library(ggplot2)
@@ -18,39 +16,83 @@ lorem2 <- p(
1816
"nunc turpis libero nascetur!"
1917
)
2018

21-
ui <- page_fixed(
22-
titlePanel("Sidebar Resize", "312 | bslib-sidebar-resize"),
23-
h2("Static plot resizing"),
24-
p(
25-
"The plot in the layout below should stretch while the sidebar is opening", "or closing. After the transition is complete, the server will update the",
26-
"plot with the final dimensions."
27-
),
28-
layout_sidebar(
29-
sidebar = sidebar(title = "Toggle me", lorem1, lorem2, lorem1),
30-
lorem1,
31-
plotOutput("plot_static"),
32-
lorem2
19+
ui <- page_navbar(
20+
title = "312 | bslib-sidebar-resize",
21+
theme = bs_theme("bslib-sidebar-transition-duration" = "3s"),
22+
sidebar = sidebar(
23+
title = "Shared Sidebar",
24+
open = "open",
25+
p("The plots should resize smoothly when this sidebar or the local sidebar are toggled.")
3326
),
34-
h2("Widget plot resizing", class = "mt-4 mb-2"),
35-
p(
36-
"The plot in the layout below should stretch while the sidebar is opening", "or closing. There should be no layout shift after the transition is", "complete."
27+
nav(
28+
"Static",
29+
h2("Static plot resizing"),
30+
p(
31+
"The plot in the layout below should stretch while the sidebar is",
32+
"opening or closing. After the transition is complete, the server will",
33+
"update the plot with the final dimensions."
34+
),
35+
layout_sidebar(
36+
sidebar = sidebar(title = "Toggle me", lorem1, lorem2, lorem1),
37+
lorem1,
38+
plotOutput("plot_static1"),
39+
lorem2
40+
),
41+
h2("Shared only", class = "my-3"),
42+
p(
43+
"The next plot should resize smoothly only when the shared sidebar is transitioning."
44+
),
45+
div(
46+
class = "row",
47+
div(class = "col", plotOutput("plot_static2")),
48+
div(class = "col", p(lorem2, lorem1))
49+
)
3750
),
38-
layout_sidebar(
39-
sidebar = sidebar(title = "Toggle me", lorem1, lorem2, lorem1),
40-
lorem1,
41-
plotlyOutput("plot_widget"),
42-
lorem2
51+
nav(
52+
"Widget",
53+
h2("Widget plot resizing", class = "mt-4 mb-2"),
54+
p(
55+
"The plot in the layout below should stretch while the sidebar is opening",
56+
"or closing. There should be no layout shift after the transition is",
57+
"complete."
58+
),
59+
layout_sidebar(
60+
sidebar = sidebar(title = "Toggle me", lorem1, lorem2, lorem1),
61+
lorem1,
62+
plotlyOutput("plot_widget1"),
63+
lorem2
64+
),
65+
h2("Shared only", class = "my-3"),
66+
p(
67+
"The next plot should resize smoothly only when the shared sidebar is transitioning."
68+
),
69+
div(
70+
class = "row",
71+
div(class = "col", plotlyOutput("plot_widget2")),
72+
div(class = "col", p(lorem2, lorem1))
73+
)
4374
),
44-
div(style = "min-height: 100vh")
75+
footer = div(style = "min-height: 100vh")
4576
)
4677

4778
server <- function(input, output, session) {
4879
plot <- reactive({
49-
ggplot(mtcars, aes(mpg, wt)) + geom_point()
80+
ggplot(mtcars, aes(mpg, wt)) +
81+
geom_point(aes(color = factor(cyl))) +
82+
labs(
83+
title = "Cars go brrrrr",
84+
x = "Miles per gallon",
85+
y = "Weight (tons)",
86+
color = "Cylinders"
87+
) +
88+
theme_gray(base_size = 16)
5089
})
5190

52-
output$plot_static <- renderPlot(plot())
53-
output$plot_widget <- renderPlotly(ggplotly(plot()))
91+
output$plot_static1 <- renderPlot(plot())
92+
output$plot_static2 <- renderPlot(plot())
93+
94+
output$plot_widget1 <- renderPlotly(ggplotly(plot()))
95+
output$plot_widget2 <- renderPlotly(ggplotly(plot()))
5496
}
5597

5698
shinyApp(ui, server)

0 commit comments

Comments
 (0)