Skip to content

Commit 1b5b56b

Browse files
committed
updated tests
1 parent 85e310f commit 1b5b56b

File tree

2 files changed

+32
-61
lines changed

2 files changed

+32
-61
lines changed

tests-manual/trigger-shown-sidebar.R

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,20 @@
11
# Run this app to test that Shiny outputs that are initally hidden inside
22
# menuItems become visible ( trigger("shown) ) after we expand the respective
3-
# menuItem. Currently, this doesn't look exactly pretty, but it does work.
4-
#
5-
# ------------------------------------------------------------------------------
6-
#
7-
# Aside from being ugly, this app also shows another unfortunate side effect
8-
# of the hacky code for the trigger("shown) of Shiny outputs. Which is that
9-
# the ensureActivatedTab() function does not work on app startup if the only
10-
# tabNamed things are initially hidden inside the menuItem parents.
11-
#
12-
# To see this, go to this app URL:
13-
# http://127.0.0.1:4601/?_inputs_&sidebarCollapsed=%22false%22&sidebarItemExpanded=%22tabName%22&smenu=null
14-
# You will see that even though `smenu` is "null" the `name` tab (menuSubItem)
15-
# appears highlighted, as it should be if the ensureActivatedTab() function is
16-
# doing its job.
17-
# But if you do this "manually", even though you get the *SAME* bookmarked URL,
18-
# you don't see the `name` tab highlighted...:
19-
# 1) Go to http://127.0.0.1:4601/
20-
# 2) Click on the "Menu Item 1" to expand it
21-
# 3) Check with abadonment and dismay that the URL looks the same as above,
22-
# but that the `name` tab is *NOT* highlighted
23-
# 4) Regain some faith and hope through the fact that at least the content
24-
# ("This is the only content") always appears, so while something if off
25-
# with ensureActivatedTab(), it's still doing its most important job,
26-
# which is to display some/any content on the dashboardBody if there is
27-
# a menuItem or menuSubItem anywhere in the dashboardSidebar with a
28-
# tabName and a corresponding tabItem anywhere in the dashboardBody
29-
#
30-
# ------------------------------------------------------------------------------
31-
#
32-
# This also shows that you can only bookmark the expanded menuItem *IF* at least
33-
# one of its children is a menuSubItem *with* a tabName.
3+
# menuItem.
344

355
library(shiny)
366
library(shinydashboard)
377

38-
options(shiny.launch.browser=F, shiny.minified=F, shiny.port = 4601)
8+
options(shiny.launch.browser=F, shiny.minified=F, shiny.port = 9000)
399

4010
ui <- function(req) {
4111
dashboardPage(
4212
dashboardHeader(),
4313
dashboardSidebar(
4414
sidebarMenu(id = "smenu",
4515
menuItem("Menu Item 1", tabName = "tab1", "text1", menuSubItem("name", tabName = "tabName")),
46-
menuItem("Menu Item 2", tabName = "tab2", textOutput("text2"))
16+
menuItem("Menu Item 2", tabName = "tab2", textOutput("text2"), startExpanded = FALSE,
17+
expandedName = "expanded")
4718
)
4819
),
4920
dashboardBody(

tests-manual/updateTabItems.R

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
## This creates dashboard with a sidebar. The sidebar has a button which allows to switch between different
22
## panels (tabs) within the same dashboard
33

4-
ui <- dashboardPage(
5-
dashboardHeader(title = "Simple tabs"),
6-
dashboardSidebar(
7-
sidebarMenu(
8-
id = "tabs",
9-
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
10-
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
11-
),
12-
actionButton('switchtab', 'Switch tab')
4+
library(shinydashboard)
5+
library(shiny)
6+
7+
options(shiny.launch.browser=F, shiny.minified=F, shiny.port = 9000)
8+
9+
ui <- dashboardPage(
10+
dashboardHeader(title = "Simple tabs"),
11+
dashboardSidebar(
12+
sidebarMenu(id = "tabs",
13+
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
14+
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
1315
),
14-
dashboardBody(
15-
tabItems(
16-
tabItem(tabName = "dashboard",
17-
h2("Dashboard tab content")
18-
),
19-
tabItem(tabName = "widgets",
20-
h2("Widgets tab content")
21-
)
22-
)
16+
actionButton('switchtab', 'Switch tab')
17+
),
18+
dashboardBody(
19+
tabItems(
20+
tabItem(tabName = "dashboard", h2("Dashboard tab content")),
21+
tabItem(tabName = "widgets", h2("Widgets tab content"))
2322
)
2423
)
24+
)
2525

26-
server <- function(input, output, session) {
27-
observeEvent(input$switchtab, {
28-
newtab <- switch(input$tabs,
29-
"dashboard" = "widgets",
30-
"widgets" = "dashboard"
31-
)
32-
updateTabItems(session, "tabs", newtab)
33-
})
34-
}
26+
server <- function(input, output, session) {
27+
observeEvent(input$switchtab, {
28+
newtab <- switch(input$tabs,
29+
"dashboard" = "widgets",
30+
"widgets" = "dashboard"
31+
)
32+
updateTabItems(session, "tabs", newtab)
33+
})
34+
}
3535

36-
shinyApp(ui, server)
36+
shinyApp(ui, server)

0 commit comments

Comments
 (0)