闪亮 - 侧边栏字幕和 div()

shiny - sidebar subtitles and div()

this question 的第二个答案之后,我在闪亮的应用程序中添加了一个“全部重置”按钮。但是,重置操作按钮似乎只有在包裹在 div() 中时才有效(原始答案没有),但是当代码包含 div() 包裹时,我的侧边栏标题(橙色文本)消失。示例代码如下,如有任何帮助,我们将不胜感激!

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

sidebar <- dashboardSidebar(
 useShinyjs(), 
 div(
    id = "form",
    subtitle = h5("Subtitle 1", style="color:orange"),
    textInput(inputId = "Init1", label = NULL, value = "1"),
    subtitle = h5("Subtitle 2", style="color:orange"),
    textInput(inputId = "Init2", label = "Lab1", value = "2"),
        
    actionButton("resetAll", "Reset all")))

server <- function(input, output, session) {
observeEvent(input$resetAll, {
    reset("form")}) 

df <- reactive({
    data.frame(Nums = as.numeric(c(input$Init1, input$Init2)), y = 0)
    }) 
                         
output$plot2 <- renderPlot({
    dat <- df()
        
    ggplot(dat) +
        geom_point(aes(x = Nums, y = y))
    })} 

ui <- dashboardPage(header = dashboardHeader(), 
sidebar = sidebar,
body = dashboardBody(
        mainPanel(plotOutput("plot2"))))
                
shinyApp(ui, server) 

删除 div,并使用 reset("sidebarCollapsed") 而不是 reset("form")

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

sidebar <- dashboardSidebar(
    useShinyjs(), 
    subtitle = h5("Subtitle 1", style="color:orange"),
    textInput(inputId = "Init1", label = NULL, value = "1"),
    subtitle = h5("Subtitle 2", style="color:orange"),
    textInput(inputId = "Init2", label = "Lab1", value = "2"),
    actionButton("resetAll", "Reset all")
)

server <- function(input, output, session) {
    observeEvent(input$resetAll, {
        reset("sidebarCollapsed")}
    ) 
    
    df <- reactive({
        data.frame(Nums = as.numeric(c(input$Init1, input$Init2)), y = 0)
    }) 
    
    output$plot2 <- renderPlot({
        dat <- df()
        ggplot(dat) +
            geom_point(aes(x = Nums, y = y))
    })} 

ui <- dashboardPage(header = dashboardHeader(), sidebar = sidebar, body = dashboardBody(mainPanel(plotOutput("plot2"))))

shinyApp(ui, server)