I added a "reset all" button to my shiny app, following the second answer to this question. However, the reset action button only seems to work when it's wrapped in div()
(which the original answer didn't have), but when the code has the div()
wrap, my sidebar titles (orange text) disappear. Sample code is below, and any help would be appreciated!
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)