I am trying to make reactive inputs to get an output and then use that output as input to calculate a function. This is just an example of what I want to do. I cannot remove the product function.
Can you suggest how to display the output. so the product has to be a result from hours and maxdays which depends on the selection of days.
library(shiny)
ui = fluidPage(
selectInput('p_id','ID:', c(111,222,333)),
uiOutput('uiID'),
uiOutput('uiID1'),
# uiOutput('val'),
textOutput("values4.5"),
submitButton("apply_changes")
)
server = function(input, output, session) {
maxdays <- reactive({
if(input$p_id %in% c(111)){
x = c(1,2)
}else{
if(input$p_id %in% c(222)){
x = 2
}else
x = 3
}
return(x)
})
hours <- reactive({
if(input$p_id %in% c(111)){
x = c(20,10)
}else{
if(input$p_id %in% c(222)){
x = 20
}else
x = 30
}
return(x)
})
output$uiID <- renderUI({
selectInput('days','Days:', choices=maxdays())
})
output$uiID1 <- renderUI({
selectInput('days','Days:', choices=hours())
})
product<-function(p_id,maxdays,hours){
prod=p_id*maxdays*hours
return(prod)
}
complete_ans <-reactive({
answer <- product(input$p_id,input$maxdays,input$hours)
values4.5 = answer
output=list(values4.5=values4.5)
})
output$values4.5 <- renderText({complete_ans()[['values4.5']]})
}
runApp(shinyApp(ui = ui, server = server))
