baj
April 3, 2019, 11:25am
1
I am trying to set up shinytest with an app that uses shinydashboard.
How can I switch to a specific tabItem? The recorder doesn' change anything it only records the sidepanel modifications but doesn't actually change the view...
i.e. the only command I found is app$setInputs(sidebarItemExpanded = "name")
I guess, I am looking for something like tabsetPanel, only for shinydashboard.
Could you please guide me the correct doc?
Thx,
B
Just to follow-up on this, there's an issue being worked on now in shinytest's github related to this problem.
opened 03:26PM - 28 Jun 18 UTC
closed 08:10PM - 07 Aug 20 UTC
I am trying to use `shinytest` to simulate the following user action within an a… pp built on `shinydashboard`:
- user clicks on a sidebar `menuItem` which expands to reveal a number of `menuSubItem`
- user clicks on a sidebar `menuSubItem` which should update the tab shown in `dashboardBody`
The code below illustrates how such an app might look. The problem is that when `recordTest(".")` is run for this app and the steps above are followed, the test script returned doesn't contain any reference to user selection of `menuSubItems`:
```
app <- ShinyDriver$new("../")
app$snapshotInit("mytest")
app$setInputs(sidebarCollapsed = FALSE)
app$setInputs(sidebarItemExpanded = "Widgets")
app$snapshot()
```
This seems related to issue #167 which has been marked as closed, but I'm still unable to resolve the problem above. I'm using the dev versions of both `shinydashboard` and `shinytest`.
```
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
## Sidebar content
dashboardSidebar(
sidebarMenu(
menuItem("Widgets", tabName = "widgets", icon = icon("globe"),
menuSubItem("Widget1", tabName = "widget1", icon = icon("blind")),
menuSubItem("Widget2", tabName = "widget2", icon = icon("blind")))
)
),
## Body content
dashboardBody(
tabItems(
# Second tab content
tabItem(tabName = "widget1", h2("Widgets1 tab content")),
# Second tab content
tabItem(tabName = "widget2", h2("Widgets2 tab content"))
)
)
)
server <- function(input, output){}
shinyApp(ui, server)
```
1 Like
This wasn't very obvious before, but sidebarMenu()
needs an id
in order for shinytest to record any click events on the sidebar. We've made this a little more clear in the documentation -- https://rstudio.github.io/shinydashboard/behavior.html#testing-with-shinytest
Hopefully that helps with your use case?
1 Like
system
Closed
April 17, 2019, 4:54pm
4
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.