I have a shiny code like in the below. I need to define variables as reactiveValues to be updatable (or I could define them I think as global but then I have to press clean objects from Rstudio which is not very user-friendly).I try to run a validate code to check for existence of the data I have defined as reactiveValues. validate(need(exists("GSEmRNA$d"),message="Dataframe not found")) yields "Dataframe not found" thus, does not plot my boxplot. If I define them as global variables and forget to press clean objects, code might mix up as old data can be passed as if it is new. Any help is appreciated.
server.R
shinyServer(function(input, output) {
observeEvent(input$GoButton,{
dataset <- data.frame(first= c(1,5,9),second=c(8,5,13), third=c(10,3,17))
GSEmRNA <- reactiveValues(d=dataset)
})
output$BoxplotDataset <- renderPlot({
if (input$GoButton== 0) {return()}
else{
validate(need(exists("GSEmRNA$d"),message="Dataframe not found"))
boxplot(GSEmRNA$d)}
})
})ui.R
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Dataset Selection"),
sidebarPanel(
actionButton("GoButton","GO")
),
mainPanel(
wellPanel(
column(8, plotOutput("BoxplotDataset")
)
)
)))
## FOR THE RECORD, I ALSO POSTED THIS QUESTION TO STACKOVERFLOW. http://stackoverflow.com/questions/35541662/shiny-check-reactivevalue-existence-with-validate-not-foundshinyServer(function(input, output) {
GSEmRNA <- reactiveValues(d=NULL)
observeEvent(input$GoButton,{
dataset <- data.frame(first= c(1,5,9),second=c(8,5,13), third=c(10,3,17))
GSEmRNA$d <- dataset
})
output$BoxplotDataset <- renderPlot({
validate(need(GSEmRNA$d,message="Dataframe not found"))
boxplot(GSEmRNA$d)}
})
})
shinyServer(function(input, output) {
GSEmRNA <- eventReactive(input$GoButton, {
data.frame(first= c(1,5,9),second=c(8,5,13), third=c(10,3,17))
})
output$BoxplotDataset <- renderPlot({
boxplot(GSEmRNA())}
})
})
--
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/13dc194a-28fa-42ef-9bf3-19fd891b49a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.