Can I use this function only once?

I want to call the arcsinT function in R shiny. The arcsinT function returns a calculation result, a picture, and the output information of the console. I want to display this all information in the UI I designed.

I implemented this function using the following code.

But in order to achieve this, I used the arcsinT function three times in the server function, one to store the calculation result, another to output the image, and one to output the console information.

Is there a way to achieve my function by just calling the arcsinT function once? Calling three times will result in too low operating efficiency.

library(shiny)
library(astrochron)
data("modelA")



ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput('data','data',c("modelA")),
      actionButton(inputId = "run",label = "RUN")
    ),
    
    mainPanel(
      plotOutput("plot"),
      verbatimTextOutput("verb"),
    )
  )
)

server <- function(input, output, session) {
  
  rv <- reactiveValues(modelA = modelA)
  
  observeEvent(input$run,
               {
      
                 rv[['results']] <- arcsinT(isolate(rv[[input$data]]),genplot = T)
                 output$plot <- renderPlot(arcsinT(isolate(rv[[input$data]]),genplot = T))
                 output$verb <- renderPrint(m <- arcsinT(isolate(rv[[input$data]]),genplot = T))
               }
  )
  
}

shinyApp(ui, server)
server <- function(input, output, session) {

  rv <- reactiveValues(modelA = modelA)

  output$plot <- renderPlot({
    req(input$run)
    shiny::isolate({
      rv[["results"]] <- arcsinT(req(rv[[input$data]]), genplot = T)
    })
  })

  output$verb <- renderPrint(
    req(rv[["results"]])
  )

}

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.