Hi,
I am having trouble stopping reactivity. I tried to put isolate around my input var, but it still changes the output even after changing on the UI display.
Is there an easy way to completely stop reactivity and only recalc on button pressed.
I have:
------------------------
library(shiny)
# Define UI for data upload app ----
ui <- fluidPage(
# App title ----
titlePanel("Uploading Files"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Action Button ----
actionButton("Execute", label = "CalcPresentValue"),
# Input: Select RA ----
numericInput("Amrt", label = h3("Interest"), value = .1),
# Input: Select a file ----
fileInput("file1", "readClaims",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
………..
# Main panel for displaying outputs ----
mainPanel(
# Output: Data file ----
tableOutput("contents")
)
)
)
server <- function(input, output) {
observeEvent(input$Execute, {
output$contents <- renderTable({
isolate( input$Amrt)
input$file1
# I do a bunch of modifications to this table and the final table is outputted on the main display.
FinalTable <- file1_final })
})
It is very difficult to see from here exactly how your app works. See the below example that you can paste and run in your own terminal showing isolate in action. As you can see it is within the renderPlot call here.
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
tabsetPanel(id = "tabset",
tabPanel("Uniform",
numericInput("unifCount", "Count", 100),
sliderInput("unifRange", "Range", min = -100, max = 100, value = c(-10, 10))
),
tabPanel("Normal",
numericInput("normCount", "Count", 100),
numericInput("normMean", "Mean", 0),
numericInput("normSd", "Std Dev", 1)
)
),
actionButton("go", "Plot")
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output){
v <- reactiveValues(doPlot = FALSE)
observeEvent(input$go, {
# 0 will be coerced to FALSE
# 1+ will be coerced to TRUE
v$doPlot <- input$go
})
observeEvent(input$tabset, {
v$doPlot <- FALSE
})
output$plot <- renderPlot({
if (v$doPlot == FALSE) return()
isolate({
data <- if (input$tabset == "Uniform") {
runif(input$unifCount, input$unifRange[1], input$unifRange[2])
} else {
rnorm(input$normCount, input$normMean, input$normSd)
}
hist(data)
})
})
}
shinyApp(ui, server)
In the last chunk within your renderPlot, you have a few lines of code. You pretty much bracketed the whole piece under iso.
I have 100s of lines of code to manipulate the an input table and the input$ appears in the beginning as a scalar multiple. Where would I exactly place the iso?