条件面板上的动画

2023-12-03

我想在我的条件面板上添加一些动画。我找到了这里提供的解决方案:闪亮条件面板的动画/过渡

我真的很喜欢这个解决方案,但我有一个问题。检查以下示例:

library(shiny)
library(shinyjs)
library(shinydashboard)

ui <- dashboardPage(
  header = dashboardHeader(title = "test"),
  sidebar = dashboardSidebar(),
  shinydashboard::dashboardBody(
    fluidPage(
      useShinyjs(),
      
      tags$head(
        tags$link(rel = "stylesheet", href = "https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.0/animate.compat.min.css"),
        tags$script(src = "https://cdnjs.cloudflare.com/ajax/libs/animateCSS/1.2.2/jquery.animatecss.min.js")
      ),
      
      fluidRow(
        textOutput("test"),
        column(2, offset = 2, actionButton("prev_box", "Previous")),
        column(
          4,
          
          # conditionalPanel(condition = "output.phase_box_ui == 0",
          #                  uiOutput("box_move1")),
          # conditionalPanel(condition = "output.phase_box_ui > 0",
          #                  uiOutput("box_move2"))
          

          animatedConditionalPanel(
            condition = "output.phase_box_ui == 0",
            onShow = animateCSS("backInRight", duration = 1000),
            onHide = animateCSS("backOutLeft", duration = 1000),
            fadeIn = 0,
            fadeOut = 0,
            uiOutput("box_move1")
          ),
          animatedConditionalPanel(
            condition = "output.phase_box_ui == 1",
            onShow = animateCSS("backInRight", duration = 1000),
            onHide = animateCSS("backOutLeft", duration = 1000),
            fadeIn = 0,
            fadeOut = 0,
            uiOutput("box_move2")
          )
          
        ),
        column(2, actionButton("next_box", "Next"))
      )
    )
  )
)

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

  #### TEST BOX MOVING
  
  phase_box = reactiveVal(0)
  
  observeEvent(phase_box(),{
    if(phase_box() == 0){
      shinyjs::hide("prev_box")
    }else{
      shinyjs::show("prev_box")
    }
  })
  
  
  observeEvent(input$prev_box,{
    if(phase_box() > 0){
      val = phase_box() - 1
      phase_box(val)
    }
  })
  
  observeEvent(input$next_box,{
    if(phase_box() < 6){
      val = phase_box() + 1
      phase_box(val)
    }
  })
  
  output$test = renderText({
    phase_box()
  })
  
  output$phase_box_ui = reactive({return(phase_box())})
  outputOptions(output, "phase_box_ui", suspendWhenHidden = F)
  
  
  
  output$box_move1 = renderUI({
    shinydashboard::infoBox(title = "First box", value = 0, color = "red")

  })
  
  
  output$box_move2 = renderUI({
    shinydashboard::infoBox(title = "Second box", value = 1)
  })
  
}

shinyApp(ui, server)

enter image description here

问题是在启动时,它们都出现一秒钟然后消失,但在启动时第一个框应该是可见的。我该如何修复它?

EDIT:

现在第一个问题已经解决了。不过请检查下面的 gif:

enter image description here

当第二个盒子到达时,它到达第一个盒子的下方,然后突然上升。如果过渡不是立即发生(它只是在正确的位置弹出),效果可能会很好。您知道有解决办法吗?看起来,就在一瞬间(在过渡期间),它们都显示出来,因此第二个框位于第一个框下方。

这是为第二个框的 inShow 过渡添加 1 秒延迟的行为。也许问题更清楚了。

enter image description here

EDIT2:

我在嵌套条件面板上有一个更大的问题。当我将另一个条件面板(一个简单的)放入动画中时,每次触发内部条件时,动画都会再次运行动画。这是一个可重现的示例:

library(shiny)
library(shinyjs)
library(shinydashboard)

ui <- dashboardPage(
  header = dashboardHeader(title = "test"),
  sidebar = dashboardSidebar(),
  shinydashboard::dashboardBody(
    fluidPage(
      useShinyjs(),
      
      tags$head(
        tags$link(rel = "stylesheet", href = "https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.0/animate.compat.min.css"),
        tags$script(src = "https://cdnjs.cloudflare.com/ajax/libs/animateCSS/1.2.2/jquery.animatecss.min.js")
      ),
      
      fluidRow(
        textOutput("test"),
        column(2, offset = 2, actionButton("prev_box", "Previous")),
        column(
          4,
          
          animatedConditionalPanel(
            condition = "output.phase_box_ui == 0",
            onShow = animateCSS("backInRight", duration = 1000),
            onHide = animateCSS("backOutLeft", duration = 1000),
            fadeIn = 0,
            fadeOut = 0,
            uiOutput("box_move1")
          ),
          animatedConditionalPanel(
            condition = "output.phase_box_ui == 1",
            onShow = animateCSS("backInRight", duration = 1000),
            onHide = animateCSS("backOutLeft", duration = 1000),
            fadeIn = 0,
            fadeOut = 0,
            uiOutput("box_move2")
          )
          
        ),
        column(2, actionButton("next_box", "Next"))
      )
    )
  )
)

server <- function(input, output,session) {
  
  #### TEST BOX MOVING
  
  phase_box = reactiveVal(0)
  
  observeEvent(phase_box(),{
    if(phase_box() == 0){
      shinyjs::hide("prev_box")
    }else{
      shinyjs::show("prev_box")
    }
  })
  
  
  observeEvent(input$prev_box,{
    if(phase_box() > 0){
      val = phase_box() - 1
      phase_box(val)
    }
  })
  
  observeEvent(input$next_box,{
    if(phase_box() < 6){
      val = phase_box() + 1
      phase_box(val)
    }
  })
  
  output$test = renderText({
    phase_box()
  })
  
  output$phase_box_ui = reactive({return(phase_box())})
  outputOptions(output, "phase_box_ui", suspendWhenHidden = F)
  
  
  
  output$box_move1 = renderUI({
    fluidPage(
      shinydashboard::infoBox(title = "First box", value = 0, color = "red"),
      selectInput("step2", "Choose:", choices = c("one", "two")), br(),
      conditionalPanel(style = "display: none",
        condition = "input.step2 == 'two'",
        h4(strong("2. This is the second step"))
      )
    )
  })
  
  
  output$box_move2 = renderUI({
    shinydashboard::infoBox(title = "Second box", value = 1)
  })
  
}

shinyApp(ui, server)

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

条件面板上的动画 的相关文章

随机推荐

  • RODBC 和 Access - 加载数据

    我正在尝试将一些数据从 Access 数据库加载到 R 中 我能找到的所有说明都说使用 odbcConnectAccess file mdb 但我似乎无法加载此函数 是否已被替换或重命名 还有其他方法可以做到这一点吗 我已经用库 RODBC
  • 适用于 Android 和 GSON 的 ProGuard

    我正在为我的 Android 项目设置 ProGuard 我的项目也使用GSON 我研究了 ProGuard 配置与 GSON 和 Android 的兼容性 并发现了 google gson 提供的这个示例https code google
  • Python Seaborn 绘制空白直方图

    我正在尝试使用 python 中的seaborn 绘制直方图 但它给我的只是一个空白的数字 这里是describe 我的专栏 代码 plt subplots figsize 7 7 sns histplot data contratos x
  • 如何动态向react-bootstrap-table列添加href?

    我在react中使用react bootstrap table作为数据表 这里从后端获取c data作为JSON对象 如何动态地将ahref添加到react bootstrap table中的列 const data id 0 name J
  • 将列表传递给 subprocess.run

    我有一个脚本 其中包含一个列表 该列表只是我想传递给的一些参数subprocess run像这样 commands bash command 1 bash command 2 这是我的代码 commands bash command 1 b
  • Pandas read_csv 更改以 0 开头的列

    我有一个脚本 可以从 csv 文件中读取一些邮政编码 邮政编码的格式如下 zipcode 75180 90672 01037 20253 09117 31029 07745 90453 12105 18140 36108 10403 764
  • Bitbucket 管道:gcloud 崩溃 (UnicodeDecodeError)

    编辑 我想指出 如果我在计算机上使用云 sdk 手动部署 则不会发生此问题 仅限管道 再次编辑 我在 gcloud 应用程序部署中添加了 verbosity debug 这是生成的内容 Do you want to continue Y n
  • Jersey REST 服务上的用户身份验证

    我正在开发一个 REST 应用程序 它使用 Jersey 框架 我想知道如何控制用户身份验证 我查了很多地方 找到最接近的文章是这样的 http weblogs java net blog 2008 03 07 authentication
  • 当 RecyclerView 正在计算布局或尝试从 recyclerview 中删除项目时滚动时,无法调用此方法

    我正在尝试从 recyclerview 中删除我的项目 但我总是收到错误 java lang IllegalStateException 无法调用此方法 RecyclerView 正在计算布局或滚动 我正在使用notify datasetc
  • DataTable Wrapper 或如何将 UI 与业务逻辑解耦

    我正在使用 Web 表单 C Asp net 众所周知 在这个模型中 UI和业务逻辑经常是混合在一起的 如何有效地将它们分开呢 我想使用的例子是 我有一个 GridView 和一个 DataTable GridView 绑定到 DataTa
  • 引用类型作为参数

    所以我深入阅读 Jon Skeet 的 C 并遇到了一些误解 比如引用类型总是通过 ref 传递 所以我决定自己做一个小实验 正如您在下面的代码中看到的 我有一个简单的 Car 类 其中一个属性在调用构造函数时初始化为 500 我还有 Nu
  • 在多个图中添加单独的箭头

    我想在用 ggplot 和 faceting 生成的 2 个图中添加箭头 问题 如何避免两个图中的箭头重复 我想为每个图添加单独的箭头 这是一个例子 library ggplot2 data frame with fake data xdf
  • Ruby 三元运算符结构

    puts bool true false 是正确的 但是 bool puts true puts false 不是 有人可以向我解释这是为什么吗 边注 bool puts true puts false 效果也很好 当您不在方法调用上添加括
  • Rails:如何将 i18n 与 Rails 4 枚举一起使用

    Rails 4 活动记录枚举很棒 但是使用 i18n 进行翻译的正确模式是什么 从Rails 5开始 所有模型都将继承自ApplicationRecord class User lt ApplicationRecord enum statu
  • SVG 未在 Windows Phone 8 Phonegap 应用程序中显示

    似乎无法找到任何答案 使用 Phonegap 并使用 SVG 图像开发 HTML5 应用程序 从 Adob e Illustrator 的 另存为 中保存它们 然后像 HTML 中的普通图像一样使用它们 img src img the im
  • 组合框中的热跟踪列表项选择

    我有一个组合框 当用户仅通过鼠标悬停来更改选择时 我需要拦截选择的更改without点击 这是为了显示有关用户将鼠标悬停在其上的项目的补充信息 CBN SELCHANGE不会完成这项工作 因为只有当用户有actually通过单击组合框项目之
  • git stash pop 和 git stash apply 之间的区别

    我一直在使用git stash pop很长一段时间 我最近了解到git stash apply命令 当我尝试它时 它的工作原理似乎与git stash pop 有什么区别git stash pop and git stash apply g
  • 快速识别用户在编辑 NSTextField 时是否按下了箭头键

    我有很多 NSTextField 我想知道用户在编辑其中之一时是否按下了方向键之一 功能 override func keyDown theEvent NSEvent switch theEvent character case NSRig
  • 如何使用 AndEngine 通过滑动来投掷/投掷球?

    我在屏幕上有一个球精灵 当我触摸并滑动该精灵时 它必须沿特定的滑动方向移动 我给那个球添加了物理原理 我想做类似的事情扔纸 谁能帮我吗 提前致谢 您需要重写 Sprite 的 onAreaTouched 方法 如下所示 您可以从 pScen
  • 条件面板上的动画

    我想在我的条件面板上添加一些动画 我找到了这里提供的解决方案 闪亮条件面板的动画 过渡 我真的很喜欢这个解决方案 但我有一个问题 检查以下示例 library shiny library shinyjs library shinydashb