How to reset action button on changing menuItem in shinydashboard

1,404 views
Skip to first unread message

Aaghaz

unread,
Nov 23, 2016, 10:23:12 AM11/23/16
to Shiny - Web Framework for R
I would like to reset the action button on changing menuItems. I have three `menuItem` and an action button called `Submit`.
 Example code is below

    library(shiny)
    library(shinydashboard)
     
      ui <- dashboardPage(
        dashboardHeader(title = "Reset Action Button"),
        dashboardSidebar(
          sidebarMenu(id = "tabs",
            menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
            menuItem("Widgets", tabName = "widgets", icon = icon("th")),
            menuItem("More", tabName = "more", icon = icon("th"))
          ),
          actionButton('Submit', 'Submit button')
        ),
        dashboardBody(
          tabItems(
            tabItem(tabName = "dashboard",
                    h2("Dashboard tab content")
            ),
            tabItem(tabName = "widgets",
                    h2("Widgets tab content")
            ),
            tabItem(tabName = "more",
                    h2("more tab content")
          )
        )
      )
      )
     
      server <- function(input, output) {
        observe(
            print(input$Submit)
        )
      }
      shinyApp(ui, server)

On switching to different menuItems, the action button should be reset to 0

3D0G

unread,
Nov 25, 2016, 12:04:15 PM11/25/16
to Shiny - Web Framework for R
Aaghaz - in the Big Picture, you can read inputs but you can't write to them (and you can write to outputs but you can't read them) and the inputs on actionButtons increase by 1 each time you click them. So it's not possible to reset the actionButton's input value to zero.

On the other hand, you can both read and write global variables and reactive values. So you can keep track of the action button status by using one of those. Set up an observeEvent for each tab change and use those to reset the designated global or reactive to 0, In the observeEvent that reacts to actionButton clicks, increment the designated value.

As you gain more experience with Shiny, you'll probably figure out an even better way to accomplish what you're trying to do.

Tom

Joe Cheng

unread,
Nov 25, 2016, 11:38:20 PM11/25/16
to 3D0G, Shiny - Web Framework for R
Aahgaz, do none of these patterns cover what you're trying to do?


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/47b590ff-6394-4e87-8a2c-b28341c19b0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shekhar Alle

unread,
Dec 21, 2017, 12:19:48 AM12/21/17
to Shiny - Web Framework for R
I have a doubt Joe.Here is what I want.
Suppose there are 2 buttons and after pressing 1st button, some logic is there for processing which will take a lot of time and there is another button which should be used to stop this action of processing. So how can it be achieved without the option of resetting the value of button.
Please reply fast.
Reply all
Reply to author
Forward
0 new messages