2
votes

I have a Shiny Dashboard with a reactive action button but the button does not update the dashboard.

I have the tabItems split out into their own files and references using source by ui.R.

The tabItem within contain just the following code.

  actionButton("go", "Go"),
  numericInput("n", "n", 50),
  plotOutput("plot")

The server.R file is also split out and references each file using source. The the relavent file contains

    randomVals <- eventReactive(input$go, {
      runif(input$n)
    })

    output$plot <- renderPlot({
      hist(randomVals())
    })

Clicking the actionbutton does not do anything within ShinyDahsboard, but if I run this code as a shiny app on it's own it works fine.

1
I have added a submit button and if I click the action button and then the submit button the plot updates. Unlike without shiny dashboard the go button just updates the plot. - Stephen Saidani

1 Answers

3
votes

You should isolate your button, like so:

Edit: as per @tospig

rm(list = ls())
library(shiny)

shinyApp(
  ui=shinyUI(basicPage(
    actionButton("go", "Go"),
    numericInput("n", "n", 50),
    plotOutput("plot")
  )),
  server=shinyServer(function(input, output, session){

    randomVals <- eventReactive(input$go, {
      runif(input$n)
    })

    output$plot <- renderPlot({
      hist(randomVals())
    })
  })
)