0
votes

I am creating a shiny interface with multiple tabs and have a couple of questions:

  1. Is it possible to create an Action button for the user to click to refresh only the tab in which the button is placed?
  2. An additional question - is it possible to refresh the entire shiny app rather than just the tab once the ActionButton is clicked?

So in ui.R we have:

actionButton("RefreshViewExperiment","Refresh Experiments!")

What should the server.R code be for the above queries?

1
1) you can update all the components with an observe statement that need to be refreshed 2) why not just 'refresh' functionality in the toolbar of the browser? - Pork Chop
Thanks for your interest. For 1) what is the code in the observe statement? For 2) I want to make it really obvious for the user to refresh rather than clicking on the small toolbar button (it may not be obvious for new users). An ActionButton will make this easier - user4687531

1 Answers

1
votes

You can add a reactive listener to your tab's content. (Not the tab itself, though.) The content will refresh, whenever you click that button.

See this example, I hope its self-explanatory.

library(shiny)

app <- shinyApp(
  ui = shinyUI(
    fluidPage(
      tabsetPanel(
        tabPanel("no1",
          actionButton("refresh", "refresh"),
          actionButton("refreshboth", "refresh both"),
          textOutput("number1")
        ),
        tabPanel("no2", 
          textOutput("number2")
        )
      )
    )
  ), 

  server = function(input, output, session){

    backgroundchange <- reactive({
      invalidateLater(1000, session)

      runif(1)
    })

    output$number1 <- renderText({
      Listener1 <- input$refresh
      ListenerBoth <- input$refreshboth

      isolate(backgroundchange())
    })

    output$number2 <- renderText({
      ListenerBoth <- input$refreshboth

      isolate(backgroundchange())
    })        
  }      
)

runApp(app)