R-Shiny中的顶部附加吐司

xmakbtuz  于 2023-06-19  发布在  其他
关注(0)|答案(1)|浏览(110)

根据Fomantic UI-文档,以下脚本生成顶部附加的toast

$.toast({
  position: 'top attached',
  title: 'Watch out!',
  message: `I am a top attached toast`
});

R Package 器shiny.semantic中,showNotification函数不遵守top attached命令,但它通常遵守位置参数,如下面提供的最小工作示例(MWE)所示。

# library
library(shiny)
library(shiny.semantic)

# application

if (interactive()) {
  
  shiny::shinyApp(
    
    ui = semanticPage(
      title = 'Title',
      actionButton(
        inputId = 'show',
        label = 'Click me!'
      ),
      actionButton(
        inputId = 'bottom_left',
        label = 'Bottom left!'
      ),
      actionButton(
        inputId = 'top_attached',
        label = 'Top attached!'
      )
    ),
    
    server = function(input,output) {
      
      observeEvent(
        input$bottom_left,
        {
          showNotification(
            ui = 'Where am I?',
            type = 'default',
            position = 'bottom left'
          )
        }
      )
      
      observeEvent(
        input$top_attached,
        {
          showNotification(
            ui = 'Where am I?',
            type = 'default',
            position = 'top attached'
          )
        }
      )
      
      observeEvent(
        input$show,
        {
          toast(
            title = 'See me!',
            message = 'Where am I?',
            toast_tags = tags$script(
              "($.toast({position: 'top attached'}))"
            )
          )
        }
      )
      
    }
    
  )
  
}

如何使用基本Rshiny.semantic使showNotificationtoast函数服从top attached命令?

icnyk63a

icnyk63a1#

虽然没有文档记录,但toast_tags接受一个命名的向量或列表。所以你对toast()的调用应该是:

toast(
  title = 'See me!',
  message = 'Where am I?',
  toast_tags = list(position = 'top attached')
)

这在您的MWE中对我有效(toast_tags = c(position = 'top attached')也是如此)

相关问题