R shiny:bslib与shinyBS之间的使用不兼容。

huangapple go评论147阅读模式
英文:

R shiny : Incompatibility of use between bslib and shinyBS

问题

我有一个带有导航栏和默认主题的Shiny应用程序。我想在我的应用程序中的一个地方添加一个帮助按钮,当鼠标移到上面时显示弹出窗口。

我注意到使用一个具有Bootstrap版本大于3的主题会阻止弹出窗口正常工作。
使用版本3时,它可以正常工作。

以下是一个可重现的示例:

  1. library(shiny)
  2. library(bslib)
  3. library(shinyBS)
  4. ui <- navbarPage(
  5. title = "Shiny",
  6. theme = bslib::bs_theme(bootswatch = "cosmo", version = 3), # 不适用于版本4或版本5
  7. tabPanel(
  8. "Tab 1",
  9. fluidPage(
  10. mainPanel(
  11. bsButton("popupBtn", label = "?", style = "info")
  12. )
  13. )
  14. )
  15. )
  16. server <- function(input, output, session) {
  17. shinyBS::addPopover(
  18. session,
  19. "popupBtn",
  20. "数据",
  21. content = paste0("我的文本"),
  22. trigger = 'hover'
  23. )
  24. }
  25. shinyApp(ui, server)

如果有人有办法使主题与版本5一起工作并显示弹出窗口,请分享。

英文:

I have a shinyapp with a navbar and a default theme.
I want to add a help button in one place in my application that displays a popup when you move the mouse over it.

I noticed that using a theme with a boostrap version > 3 inhibited the popup from working.
with version = 3 it works normally

Here is a reproducible example :

  1. library(shiny)
  2. library(bslib)
  3. library(shinyBS)
  4. ui &lt;- navbarPage(
  5. title = &quot;Shiny&quot;,
  6. theme = bslib::bs_theme(bootswatch = &quot;cosmo&quot;, version = 3), # not working with version = 4 or version = 5
  7. tabPanel(
  8. &quot;Tab 1&quot;,
  9. fluidPage(
  10. mainPanel(
  11. bsButton(&quot;popupBtn&quot;, label = &quot;?&quot;, style = &quot;info&quot;)
  12. )
  13. )
  14. )
  15. )
  16. server &lt;- function(input, output, session) {
  17. shinyBS::addPopover(
  18. session,
  19. &quot;popupBtn&quot;,
  20. &quot;Data&quot;,
  21. content = paste0(&quot;Mon texte&quot;),
  22. trigger = &#39;hover&#39;
  23. )
  24. }
  25. shinyApp(ui, server)

If anyone has a trick to make the theme work with version = 5 and the popup

答案1

得分: 1

以下是已翻译的内容:

这是方法:

  1. library(shiny)
  2. library(bslib)
  3. js &lt;- &quot;
  4. $(document).ready(function() {
  5. var popoverTriggerList =
  6. [].slice.call(document.querySelectorAll(&#39;[data-bs-toggle=popover]&#39;));
  7. var popoverList = popoverTriggerList.map(function(popoverTriggerEl) {
  8. return new bootstrap.Popover(popoverTriggerEl);
  9. })
  10. });
  11. &quot;
  12. ui &lt;- navbarPage(
  13. tags$head(tags$script(HTML(js))),
  14. title = &quot;Shiny&quot;,
  15. theme = bslib::bs_theme(bootswatch = &quot;cosmo&quot;, version = 5),
  16. tabPanel(
  17. &quot;Tab 1&quot;,
  18. fluidPage(
  19. mainPanel(
  20. actionButton(
  21. &quot;popupBtn&quot;,
  22. label = &quot;?&quot;,
  23. `data-bs-toggle` = &quot;popover&quot;,
  24. title = &quot;Popover title&quot;,
  25. `data-bs-content` =
  26. &quot;And here&#39;s some amazing content. It&#39;s very engaging. Right?&quot;
  27. )
  28. )
  29. )
  30. )
  31. )
  32. server &lt;- function(input, output, session) {
  33. }
  34. shinyApp(ui, server)

这里是文档。

R shiny:bslib与shinyBS之间的使用不兼容。

英文:

Here is the way:

  1. library(shiny)
  2. library(bslib)
  3. js &lt;- &quot;
  4. $(document).ready(function() {
  5. var popoverTriggerList =
  6. [].slice.call(document.querySelectorAll(&#39;[data-bs-toggle=popover]&#39;));
  7. var popoverList = popoverTriggerList.map(function(popoverTriggerEl) {
  8. return new bootstrap.Popover(popoverTriggerEl);
  9. })
  10. });
  11. &quot;
  12. ui &lt;- navbarPage(
  13. tags$head(tags$script(HTML(js))),
  14. title = &quot;Shiny&quot;,
  15. theme = bslib::bs_theme(bootswatch = &quot;cosmo&quot;, version = 5),
  16. tabPanel(
  17. &quot;Tab 1&quot;,
  18. fluidPage(
  19. mainPanel(
  20. actionButton(
  21. &quot;popupBtn&quot;,
  22. label = &quot;?&quot;,
  23. `data-bs-toggle` = &quot;popover&quot;,
  24. title = &quot;Popover title&quot;,
  25. `data-bs-content` =
  26. &quot;And here&#39;s some amazing content. It&#39;s very engaging. Right?&quot;
  27. )
  28. )
  29. )
  30. )
  31. )
  32. server &lt;- function(input, output, session) {
  33. }
  34. shinyApp(ui, server)

Here is the documentation.

R shiny:bslib与shinyBS之间的使用不兼容。

huangapple
  • 本文由 发表于 2023年8月4日 23:14:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76837215.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定