Shinyapp runs slow when published

Hey!!
I created a very simple password generator and it worked perfect (well, as much as i managed) when tested from RStudio but when i uploaded it online it seems to function really bad /:slight_smile:

What am i doing wrong?
https://psychisrael.shinyapps.io/passgen/

Code (single file):

library(shiny)
library(stringr)

pass <- function(pass_length=8,pass_num=10,use.signs=F,pin=NULL,signs="@#$^%"){
  if(use.signs){require("stringr")}
  set.seed(pin)
  pass.ops <- c(LETTERS,letters,0:9)
  signs=unlist(stringr::str_split(signs,pattern = ""))
  if(use.signs){pass.ops=c(pass.ops,signs)}
  password <- function(pass_length){
    paste(sample(pass.ops,
                 pass_length,T),collapse = "")}
  pass <- c()
  for(i in 1:pass_num){
    pass[i] <- password(pass_length)
  }
  return(data.frame(pass))
}
####
# Define UI for application
ui <- fluidPage(
    # Application title
    titlePanel("Password Generator"),

    sidebarLayout(
        sidebarPanel(
            sliderInput("passlength",
                        label = "Number of characters",
                        min = 4,
                        max = 30,
                        value = 8),

            numericInput("pass_num",
                         label = "Passwords to generate",
                         value = 5,min = 5,max=50,step=5),

            checkboxInput("signs",label = "Use symbols"),
            conditionalPanel("input.signs==TRUE",
                             textInput("sign_examp",label = "Symbols:",
                                       value ="!@#$%^&*.~`;")),
            downloadButton("download",
                           "Download passwords",
                           icon("lock"))   ),

        mainPanel(
           tableOutput("final_pass")        )    )   )

# Define server logic
server <- function(input, output) {
    x <- reactive({
      pass(pass_length = input$passlength,
           pass_num = input$pass_num,
           use.signs= input$signs,
           signs = input$sign_examp)
    })
    output$final_pass <- renderTable({x()})

    output$download <- downloadHandler(
      filename = function(){
        paste("pass",Sys.Date(),".csv",sep = "")
      },
      content = function(file){
        write.csv(x(),file,row.names = F)      }    )   }

# Run the application
shinyApp(ui = ui, server = server)

Hi!

Taking a quick glance at your code, it seems that a good place to start would be to remove this line:
if(use.signs){require("stringr")} , as you have already loaded this pkg on app start-up (and this will run everytime you call your pass() function when use.signs is TRUE).

HTH

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.