在 Shiny 中的标题中添加进度表(shinydashboard/shinydashboardplus)

问题描述 投票:0回答:2

我有一个闪亮的应用程序,使用闪亮仪表板和闪亮仪表板Plus。在标题中,我可以添加一个 switchInput 以允许用户在两个选项之间切换。当选项更改时,整体 UI(相当复杂)会更新,以根据用户选择更改各种标签。此过程需要几秒钟,导致应用程序无响应,因此我想在 switchInput 旁边添加进度表或微调器,但我的所有尝试都失败了。 (我尝试添加来自shinydashboardPlus和shinyWidgets的进度条,但这些实际上都没有出现在标题上。)

编辑:也许有关我的用例的更多详细信息会有所帮助。当用户单击切换按钮时,我调用一个分多个步骤运行的函数,整个函数大约需要 20 秒。在每个步骤之后,我想更新进度条或微调器,以提示用户正在发生某些事情。另外,在单击之前和函数返回之后,我想隐藏进度条或微调器。

这是一些非常简化的代码,其中包含 switchInput 的标头。

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyWidgets)

# Define UI for application that draws a histogram
ui <- dashboardPage(skin = 'blue', 
                    
shinydashboardPlus::dashboardHeader(title = 'Example',
    leftUi = tagList(
        switchInput(inputId = 'swtLabels', label = 'Labels', value = TRUE,
                    onLabel = 'Label 1', offLabel = 'Label 2',
                    onStatus = 'info', offStatus = 'info', size = 'mini', 
                    handleWidth = 230)
        )
    ),
    dashboardSidebar(),
    dashboardBody()
)

server <- function(input, output) {}

# Run the application 
shinyApp(ui = ui, server = server)
r shiny shinydashboard shinydashboardplus
2个回答
1
投票

这接近您的预期吗? progress bar on dashboard header

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyWidgets)


# Define UI for application that draws a histogram
ui <- dashboardPage(skin = 'blue', 
                    
                    shinydashboardPlus::dashboardHeader(title = 'Example',
                                                        leftUi = tagList(
                                                          switchInput(inputId = 'swtLabels', label = 'Labels', value = TRUE,
                                                                      onLabel = 'Label 1', offLabel = 'Label 2',
                                                                      onStatus = 'info', offStatus = 'info', size = 'mini', 
                                                                      handleWidth = 230),
                                                          shinydashboardPlus::progressBar(
                                                                        value = 100,
                                                                        striped = TRUE,
                                                                        animated = TRUE,
                                                                        label = "loading...100%"
                                                                      )
                                                           )
                                                        ),
                    
                    
                    dashboardSidebar(),
                    dashboardBody()
                
)

server <- function(input, output) {}

# Run the application 
shinyApp(ui = ui, server = server)

0
投票

不确定您是否能够解决

Nov 3, 2021
的评论中的问题。

即,

Error in if (name != "li" || !is.null(class) || class != "dropdown") { : missing value where TRUE/FALSE needed
在我的例子中,我尝试发送自定义
tagList
作为
leftUI
tagList
的一部分,并得到了相同的错误。

阅读代码让我意识到它需要列表元素中的

name
属性,手动添加它甚至将其设置为
""
都可以。

shinyWidgets::progressBar()
在它返回的最终对象中可能没有
name
属性,因此会引发错误。我不确定为什么这里有如此严格的要求。

我只是将这个上下文留在这里,供将来偶然发现此错误的任何人使用。

© www.soinside.com 2019 - 2024. All rights reserved.