Optimizing a shiny server.R code

Hello guys, I am here with a problem. Actually I have to optimize a server.R code for a shiny app. Lets see the code first.
Actually the reactive functions are called four times after uploading every file for generating the plots. It should be only one call . How can I use the values in these output scopes without calling the functions every time. I am having error with global variables. How can I do it?

Thanks in advance.

**Note: I am very new at shiny. Pardon my mistakes.

Hello,

We cannot see your Shiny UI code, but does the user have to upload 4 different files before you want them to be processed? If that's the case, you can create a button that says: "Create plots now" or something and put all the logic for generating plots in there so it's only executed once when the button is clicked.

If this is not the case, try to create a Shiny Reprex. Shiny debugging and reprex guide

Good luck,
PJ

hello @pieterjanvc thanks for the reply. Here is my ui.R codes:

library(shiny)
shinyUI(fluidPage(
  titlePanel("File Input"),
  sidebarLayout(
    sidebarPanel(
      fileInput("file","Upload the file")
    ),
    mainPanel(
      plotOutput("plot1"),
      plotOutput("plot2"),
      plotOutput("plot3"),
      plotOutput("plot4")
    )
  )
))

The user have to upload only one file. All the four plots will based on the file.

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.