0

For example:

        data_cbs <- reactive({ 
        "code"
        })

        model <- reactive({
                data <- data_cbs()
                + "code"    
        })

Is it possible to use the following structure in R shiny?

Maybe it is important to know, that data_cbs() and model consists of 3-4 "else-if" statements.

3
  • u should use data as data() Commented Nov 16, 2016 at 12:52
  • @PorkChop sorry, it was a typo. Take a look please once more. Commented Nov 16, 2016 at 12:55
  • yeah you can do that, like a pipeline. Additionally, you can bind model to eventReactive so it only responds when data_cbs is complete Commented Nov 16, 2016 at 12:57

1 Answer 1

2

Here's a single-script example to show that this indeed works and to play around with:

# Global variables can go here
n <- 200


# Define the UI
ui <- bootstrapPage(
  checkboxInput('random', 'randomize'),
  plotOutput('plot')
)


# Define the server code
server <- function(input, output) {

  checkRandom <- reactive({
    if( input$random ){
      data <- runif(n)
    }else {
      data <- seq(1, n)
    }
    return(data)
  })

  output$plot <- renderPlot({
    plot(checkRandom())
  })
}

# Return a Shiny app object
shinyApp(ui = ui, server = server)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.