css - Multiple notifications in different places shiny app -
i made simple example show problem, is:
- how set notifications @ different places independently of each others (let's want each notification displayed @ top right , left, respectively)
```
library(shiny) ui <- fluidpage( # tags$head( # tags$style( # html(".shiny-notification { # position: fixed; # top: 800px; # left: 40px; # width: 15em; # opacity: 1; # } # " # ) # ) # ) actionbutton("showme", "show notification:") ) server <- function(input, output, session) { observe({ shownotification( id = "welcome_notif", "blablablablabla .... blablablabla.", duration = 20, closebutton = true, type = "message") }) observeevent(input$showme,{ shownotification( id = "showme_notif", "hihihi", # put text in notification duration = 30, closebutton = true, type = "message") }) } shinyapp(ui = ui, server = server)
```
i saw there special css notification in shiny code (https://github.com/rstudio/shiny/blob/master/inst/www/shared/shiny.css).
if change css class (as shown in commented code), manage change place notifications displayed (but not independently).
edit:
i tried use addclass shinyjs:
library(shiny) library(shinyjs) ui <- fluidpage( useshinyjs(), inlinecss(list(.customclass = "position: fixed; top: 200px;")), actionbutton("showme", "show notification:") ) server <- function(input, output, session) { observe({ shownotification( id = "welcome_notif", "blablablablabla .... blablablabla.", duration = 20, closebutton = true, type = "message") }) observeevent(input$showme,{ shownotification( id = "showme_notif", "hihihi", # put text in notification duration = 30, closebutton = true, type = "message") }) observe({ addclass(id = "showme_notif", class = "customclass") }) } shinyapp(ui = ui, server = server)
as suggested florian (see below) seems can handle elements generated in ui , not in server notifications.
for example works:
if (interactive()) { shinyapp( ui = fluidpage( useshinyjs(), inlinecss(list(.customclass = "position: fixed; top: 200px;")), p(id = "element", "watch happens me") ), server = function(input, output) { observe({ addclass(id = "element", class = "customclass") }) } ) }
i able modify css of element, since notification gets id: shiny-notifaction-xxx
xxx
name of notification. notifications put in container, , unable modify css want.
library(shiny) ui <- fluidpage( tags$style("#shiny-notification-showme_notif {margin:20px;}"), actionbutton("showme", "show notification:") ) server <- function(input, output, session) { observe({ shownotification( id = "welcome_notif", "blablablablabla .... blablablabla.", duration = 200, closebutton = true, type = "message") }) observeevent(input$showme,{ shownotification( id = "showme_notif", "hihihi", # put text in notification duration = 300, closebutton = true, type = "message") }) } shinyapp(ui = ui, server = server)
Comments
Post a Comment