rstudio / shinytest

Automated testing for shiny apps
https://rstudio.github.io/shinytest/
Other
225 stars 55 forks source link

shinyWidgets with ShinyTest #350

Closed wilfriedmonangeIRSN closed 4 years ago

wilfriedmonangeIRSN commented 4 years ago

Hi,

I got an error using shinyWidgets (from https://github.com/dreamRs/shinyWidgets) with the ShinyTest package. My UI part use radioGroupButtons with multiple conditionalPanel as presented below. My app works fine without ShinyTest.

  radioGroupButtons(
          inputId = "workshop",
          choices = c("<i class='fa fa-home'></i>" = "home",
                      "<i class='fa fa-edit'></i>" = "modif",
                      "<i class='fa fa-clipboard-check'></i>" = "verif",
                      "<i class='fa fa-print'></i>" = "publish"),
          justified = TRUE
    ),

    conditionalPanel(condition = "input.workshop == 'home'",
                     sidebarMenu(
                       id = 'menu_home',
                       menuItem("Acceuil", tabName = "home_welcome", icon = icon("home")),
                       menuItem("Ajouter des normes", tabName = "home_add_norme", icon = icon("plus")),
                       menuItem("Etat des serveurs", tabName = "home_server_status", icon = icon("dashboard")),
                       menuItem("Configuration", tabName = "home_config", icon = icon("cog")),
                       menuItem("Aide", tabName = "home_help", icon = icon("question-circle"))
                     )         
    ),

    conditionalPanel(condition = "input.workshop == 'modif'",
                     sidebarMenu(
                       id = 'menu_modif',
                       menuItem("Liste des normes", tabName = "modif_list_norme", icon = icon("list")),
                       # HTML('<li id="azerty"> <a href="#shiny-tab-modif_properties" data-toggle="tab" data-value="modif_properties">  <i class="fa fa-address-card"></i> <span>Propriété</span> </a>  </li>'),
                       menuItem("Propriété", id = "menu_modif_properties", tabName = "modif_properties", icon = icon("address-card")),
                       menuItem("Ajout de points", id = "menu_modif_add_points", tabName = "modif_add_points", icon = icon("plus")),
                       menuItem("Graphe personalisé /1", id = "menu_modif_visu1", tabName = "modif_visu1", icon = icon("chart-bar")),
                       menuItem("Graphe personalisé /2", id = "menu_modif_visu2", tabName = "modif_visu2", icon = icon("chart-bar")),
                       menuItem("Minium par cas", id = "menu_modif_min1", tabName = "modif_min1", icon = icon("chart-bar")),
                       menuItem("Miniums", id = "menu_modif_min2", tabName = "modif_min2", icon = icon("chart-bar")),
                       menuItem("Tableau de valeurs", id = "menu_modif_tab1", tabName = "modif_tab1", icon = icon("table")),
                       menuItem("Administration", id = "menu_modif_admin", tabName = "modif_admin", icon = icon("code-branch")),
                       menuItem("Aide", tabName = "modif_help", icon = icon("question-circle")),
                       br(),
                       actionButton('modif_refresh', span(HTML("&nbsp"), "Actualiser"), icon = icon("sync"))
                     )
    ),

The error I get when I click on the radioGroupButtons is :

app$setInputs(menu_home = "modif_list_norme")
Error in sd_getAllValues(self, private, input, output, export) :
  Unable to fetch all values from server. Is target app running with options(shiny.testmode=TRUE?)

Where is my mistake ?

Thanks

wch commented 4 years ago

The menu_home input is a sidebarMenu(), not a radioGroupButtons().

Is the sidebarMenu() from shinydashboard?

wilfriedmonangeIRSN commented 4 years ago

Sorry, made a mistake in my issue, the command that fail is

> app <- ShinyDriver$new("/xxxxx/")
Warning message:
In check("input", inputs) :
  Possible duplicate input widget ids: labsdrop, paramsdrop, filterdrop, codedrop
> app$snapshotInit("LV2_SelPu_Eau_refEau")
> app$setInputs(workshop = "modif")
Error in sd_getAllValues(self, private, input, output, export) : 
  Unable to fetch all values from server. Is target app running with options(shiny.testmode=TRUE?)
> 

Yes sidebarMenu() comes from shinydashboard.

hadley commented 4 years ago

I'd recommend starting by resolving the warning about duplicate ids.

wilfriedmonangeIRSN commented 4 years ago

I fix the warning about duplicate ids (I basically remove the code that make these warnings), but I still get the same error:

> app <- shinytest::ShinyDriver$new("/xxxx/")
> app$snapshotInit("LV2_SelPu_Eau_refEau")
> app$setInputs(workshop = "modif")
Error in sd_getAllValues(self, private, input, output, export) : 
  Unable to fetch all values from server. Is target app running with options(shiny.testmode=TRUE?)
wilfriedmonangeIRSN commented 4 years ago

Finally, I find my error. I exported a value coming from a shiny::validate whose condition was not met:

results <- reactive({
    shiny::validate(need(nrow(data$results) > 0, "xxx"))
    data$results
  })

  exportTestValues(results = { results() })

I simply add try around and everything goes fine now.

exportTestValues(results = { try(results()) })