merlinoa/shinyFeedback

Compatability with shinydashboard?

Closed this issue · 3 comments

snackbars don't seem to appear when using the shinydashboard package.
Placing the "useShinyFeedback()" function directly under "dashboardPage( ... )" throws an error and prevents the app from running. dashboardBody( ... ) was the highest level that it could fall under without causing the error and app failure but I noticed that the snackbars didn't appear when they should.

Minimal example:

library(shiny)
library(shinydashboard)
library(shinyjs)
library(shinyFiles)
library(shinyFeedback)
ui <- dashboardPage(skin = "blue",
                    dashboardHeader(title="A Shiny App"),
                    dashboardSidebar(sidebarMenu(menuItem("Data Import", tabName = "data_import", icon=icon("import", lib = "glyphicon")),
                    )
                    ),
                    dashboardBody(useShinyFeedback(),
                                  tabItems(
                                    tabItem(tabName = "data_import",
                                            h2("Data Import"),
                                            fluidRow(
                                              box(
                                                actionButton(inputId = "upload", label = "Upload Data", icon = icon("upload", lib="font-awesome")), snackbar("upload.verb", message = "Data has been uploaded!")
                                              )
                                            )
                                    ),
                                  )
                    )
)
server <- function(input, output, session) {
  expdata <- reactiveValues()
  observeEvent(input$upload,{
    expdata$an.object <- "a.thing"
    showSnackbar("upload.verb")
  })
}
shinyApp(ui = ui, server = server)

Thanks @JulianSpagnuolo

You are correct in placing the call to useShinyFeedback() inside dashboardBody(). This issue is not actually with shinydashboard, but was caused by having a "." in the id argument to snackbar() and showSnackbar(). I was not escaping the "." in the id passed to javascript, but I just pushed an update to GitHub. You can download the development version using:

devtools::install_github("merlinoa/shinyFeedback")

And you should be able to run this slightly modified version of your above app:

library(shiny)
library(shinydashboard)
library(shinyFeedback)

ui <- dashboardPage(
  skin = "blue",
  dashboardHeader(
    title="A Shiny App"
  ),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Data Import", tabName = "data_import", icon=icon("import", lib = "glyphicon"))
    )
  ),
  dashboardBody(
    useShinyFeedback(),
    tabItems(
      tabItem(
        tabName = "data_import",
        h2("Data Import"),
        fluidRow(
          box(
            actionButton(
              inputId = "upload",
              label = "Upload Data",
              icon = icon("upload", lib="font-awesome")
            ),
            snackbar(
              "upload.verb",
              message = "Data has been uploaded!"
            )
          )
        )
      )
    )
  )
)

server <- function(input, output, session) {

  observeEvent(input$upload,{
    showSnackbar("upload.verb")
  })
}

shinyApp(ui = ui, server = server)

Alternatively you can rename the "id" argument to remove the period and it should work with the CRAN version of shinyFeedback

I am closing this issue. Please reopen if it is not solved for you.

Thanks for the speedy support - it was fantastic to have an easy way to retrospectively add some verbosity to my full sized app!