-
-
Save jcheng5/3499a8201b8cb98b4593c8bce9fc6737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
ui <- shinyUI(fluidPage( | |
titlePanel("test data clipping"), | |
sidebarLayout( | |
sidebarPanel( | |
actionButton('inDataGen', 'Generate dataset'), | |
br(), | |
br(), | |
numericInput( | |
'inDataClipMin', | |
'Clip data below threshold:', | |
value = NULL, | |
width = 200, | |
step = .1 | |
), | |
numericInput( | |
'inDataClipMax', | |
'Clip data above threshold:', | |
value = NULL, | |
width = 200, | |
step = .1 | |
), | |
actionButton('inDataClipReset', 'Reset data clipping') | |
), | |
mainPanel(plotOutput("plotHist", width = "100%")) | |
) | |
)) | |
server <- shinyServer(function(input, output, session) { | |
# generate random dataset | |
dataIn <- eventReactive(input$inDataGen, { | |
cat(file = stderr(), '\nuserDataGen\n') | |
rnorm(1000) | |
}) | |
observeEvent(dataIn(), { | |
resetClip() | |
}, priority = 10) | |
resetClip <- function() { | |
updateNumericInput(session, "inDataClipMin", value = min(dataIn())) | |
freezeReactiveValue(input, "inDataClipMin") | |
updateNumericInput(session, "inDataClipMax", value = max(dataIn())) | |
freezeReactiveValue(input, "inDataClipMax") | |
} | |
observeEvent(input$inDataClipReset, { | |
resetClip() | |
}) | |
dataClip <- reactive({ | |
dm <- dataIn() | |
dm[dm > input$inDataClipMin & dm < input$inDataClipMax] | |
}) | |
output$plotHist <- renderPlot({ | |
dm = dataClip() | |
cat(file = stderr(), 'plotHist \n') | |
if (is.null(dm)) | |
return(NULL) | |
else { | |
plot(hist(dm)) | |
Sys.sleep(2) | |
} | |
}) | |
}) | |
shinyApp(ui = ui, server = server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment