In a typical Shiny app, the outputs
are merely artifacts to display some result in the UI. I would recommend utilizing reactive
elements that you can place in one or more outputs. You will find it much easier to add new features and iterate on the UI of your app. Here is a modified version that accomplishes what you're looking for:
library(shiny)
ui <- fluidPage(
numericInput("x", label = "number", value = 150),
textOutput("n1out"),
textOutput("n2out"),
textOutput("n3out")
)
f = function(x){
return(x^2)
}
g = function(x){
return(x^3)
}
server <- function(input, output) {
n1 <- reactive({
f(input$x)
})
n2 <- reactive({
g(input$x)
})
n3 <- reactive({
n1() - n2()
})
output$n1out = renderText({
print(n1())
})
output$n2out = renderText({
print(n2())
})
output$n3out = renderText({
print(n3())
})
}
shinyApp(ui, server)
I am not sure what you were trying to do with those system.time
calls Once you make the paradigm shift to do your app's processing in reactives, it will set you up for success in making your app's outputs much more streamlined.