bslib嵌套卡片全屏行为只能显示嵌套卡片吗?

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

Can bslib nested card fullscreen behavior show just the nested card?

问题

When I use the option full_screen = TRUE with nested cards, clicking the fullscreen icon maximizes both cards. Can it be set to show just the internal card as fullscreen?

当我使用选项 full_screen = TRUE 与嵌套的 card 时,点击全屏图标会使两个卡片都最大化。是否可以设置仅显示内部卡片为全屏?

英文:

When I use the option full_screen = TRUE with nested cards, clicking the fullscreen icon maximizes both cards. Can it be set to show just the internal card as fullscreen?

  1. library(shiny)
  2. library(bslib)
  3. ui = page(
  4. card(
  5. full_screen = F,
  6. card_header(
  7. "Main card",
  8. ),
  9. card(
  10. full_screen = T,
  11. card_header(
  12. "Plot card"
  13. ),
  14. plotOutput("plot")
  15. # )
  16. )
  17. )
  18. )
  19. server = function(input, output)
  20. {
  21. output$plot = renderPlot(hist(rnorm(100)))
  22. }
  23. shinyApp(ui, server)

答案1

得分: 1

这是使用JavaScript的解决方案:

  1. library(shiny)
  2. library(bslib)
  3. # 定义自定义JavaScript
  4. js <- '
  5. function toggleFullscreen(element) {
  6. if (!document.fullscreenElement) {
  7. element.requestFullscreen().catch(console.log);
  8. } else {
  9. document.exitFullscreen();
  10. }
  11. }
  12. $(document).on("shiny:connected", function() {
  13. $("#nestedCard").on("click", function() {
  14. toggleFullscreen(document.querySelector("#nestedCard"));
  15. });
  16. });
  17. '
  18. ui = page(
  19. headerPanel("Nested Fullscreen Card"),
  20. mainPanel(
  21. tags$head(tags$script(HTML(js))), # 注入自定义JS
  22. tags$div(
  23. id = "mainCard",
  24. class = "card",
  25. tags$div(
  26. class = "card-body",
  27. tags$h5("Main card", class = "card-title"),
  28. tags$div(
  29. id = "nestedCard",
  30. class = "card",
  31. tags$div(
  32. class = "card-body",
  33. tags$h5("Plot card", class = "card-title"),
  34. plotOutput("plot")
  35. )
  36. )
  37. )
  38. )
  39. )
  40. )
  41. server = function(input, output)
  42. {
  43. output$plot = renderPlot(hist(rnorm(100)))
  44. }
  45. shinyApp(ui, server)

bslib嵌套卡片全屏行为只能显示嵌套卡片吗?

英文:

Here is solution using Javascript:

  1. library(shiny)
  2. library(bslib)
  3. # Define custom JavaScript
  4. js &lt;- &#39;
  5. function toggleFullscreen(element) {
  6. if (!document.fullscreenElement) {
  7. element.requestFullscreen().catch(console.log);
  8. } else {
  9. document.exitFullscreen();
  10. }
  11. }
  12. $(document).on(&quot;shiny:connected&quot;, function() {
  13. $(&quot;#nestedCard&quot;).on(&quot;click&quot;, function() {
  14. toggleFullscreen(document.querySelector(&quot;#nestedCard&quot;));
  15. });
  16. });
  17. &#39;
  18. ui = page(
  19. headerPanel(&quot;Nested Fullscreen Card&quot;),
  20. mainPanel(
  21. tags$head(tags$script(HTML(js))), # Inject custom JS
  22. tags$div(
  23. id = &quot;mainCard&quot;,
  24. class = &quot;card&quot;,
  25. tags$div(
  26. class = &quot;card-body&quot;,
  27. tags$h5(&quot;Main card&quot;, class = &quot;card-title&quot;),
  28. tags$div(
  29. id = &quot;nestedCard&quot;,
  30. class = &quot;card&quot;,
  31. tags$div(
  32. class = &quot;card-body&quot;,
  33. tags$h5(&quot;Plot card&quot;, class = &quot;card-title&quot;),
  34. plotOutput(&quot;plot&quot;)
  35. )
  36. )
  37. )
  38. )
  39. )
  40. )
  41. server = function(input, output)
  42. {
  43. output$plot = renderPlot(hist(rnorm(100)))
  44. }
  45. shinyApp(ui, server)

bslib嵌套卡片全屏行为只能显示嵌套卡片吗?

答案2

得分: 0

问题已在较新版本的 bslib 中得到解决:
https://github.com/rstudio/bslib/issues/558

英文:

The problem has been fixed in a newer version of bslib:
https://github.com/rstudio/bslib/issues/558

huangapple
  • 本文由 发表于 2023年5月14日 12:01:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76245761.html
匿名

发表评论

匿名网友

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

确定