Patrick Balada
Patrick Balada

Reputation: 1450

Shiny in R: How can I send a number from server to ui?

For layout reasons, I try to send a single number (number of plots for example) form server to ui. Moreover, I'd like to use this number then to define the width of a box.

Is this possible? And if, how? Thank you very much for your help.

Upvotes: 1

Views: 179

Answers (1)

Syamanthaka
Syamanthaka

Reputation: 1327

I think if I understand correct, you would want to achieve the following:

  1. Input Field in ui sends a value to server.
  2. Server processes that, and generates a resulting value
  3. The generated value from step 2 goes back to become a part of another input field or probably same input field as Step 1.

You could do something like this in the server:

shinyServer(func = function(input, output, session) {
    field1_options <- reactive({
       if (!is.null(input$field1)) {
          method1(input$field1)
       } else {
          method2(input$field1) 
       }
    })

    observe({
       updateSelectInput(
       session,
       inputId = "field2",
       choices=field1_options())
    })
}

What this does is simply use the value from field1 to calculate and populate field2, here i've used example of Select Input.

Upvotes: 1

Related Questions