Reputation: 213
I'd like to be able to use results of an input in the Ui part of my shiny app, to set the default value and the maximum of a numericInput.
Here is the "idea" of the ui part i'd like :
ui <- (
numericInput("n21","choose input1",min=0,max=100000,value=5107,step=1),
numericInput("n22","choose input2",min=0,max=2000,value=1480.3/40),
# here i'd like to define value and max with the result of inputs (n23)
numericInput(inputId="nb_rows","Number of rows to show",value=n23,min=1,max=n23)
tableOutput(outputId = "data")
)
And the server part :
server <- function(input,output,session){
....
RE <- reactive({
n21 <- input$n21
n22 <- input$n22
n23 <- n21%/%n22
return(head(data, n=input$nb_rows))
})
output$data <- renderTable({RE()})
}
Any suggestions?
Upvotes: 0
Views: 29
Reputation: 302
You will need to use the observe function to change the numericinput that you want to change so we will do:
`server <- function(input,output,session){
....
RE <- reactive({
n21 <- input$n21
n22 <- input$n22
n23 <- n21%/%n22
return(n23)
})`
` observe({
x <- RE()
# Can use character(0) to remove all choices
if (is.null(x))
x <- character(0)
# Can also set the label and select items
updateNumericInput(session, "nb_rows",
label = "Number of rows to show",
value = x,
min = 1,
max = x
)
})`
And then you re-make the output table function
I hope it helps.
Upvotes: 1