Nirmalya Lahiri
Nirmalya Lahiri

Reputation: 71

Variable names are limited to 10000 bytes

I am getting error while running the code in shiny-server only. When I am running the same code from R console using runApp() function it is running well. See the error message below....

Warning: Error in assign: variable names are limited to 10000 bytes
Stack trace (innermost first):
    46: assign
    45: wrapFunctionLabel
    44: public_bind_env$initialize
    43: Observable$new
    42: reactive
    41: templateServer
    40: server [/home/shiny-apps/ACCPlantAnalysis/server.R#20]
     1: runApp
Error in assign(name, func, environment()) : 
  variable names are limited to 10000 bytes

Line no 41 and 40 are written by me. but other lines are not written by me; call from any reference library. I don't know from which library.

Upvotes: 4

Views: 7429

Answers (3)

Nirmalya Lahiri
Nirmalya Lahiri

Reputation: 71

At last I got solution. I wrote functions for every 'if' block and put all code of 'if' block inside the function. Then call the function. And the was problem solved.

SectoralLeverageRatio(){
...
...
}

if (selectedIndex=="Sectoral Leverage Ratio"){
  SectoralLeverageRatio()
}

The conclusion is... if your 'if' block is large enough and you got 'variable names are limited to 10000 bytes' error. Replace the code inside the 'if' block with user defined function.

This is the problem of shiny-server; not the problem of 'R'. If you run your code from 'R' console using runApp(), you would not get any error. But if you run through(production environment) you might get an error.

Upvotes: 3

Nirmalya Lahiri
Nirmalya Lahiri

Reputation: 71

after a day long research I am able to pinpoint the issue. I have a long if..else block in my code. There are 10 if block and every if block has at least 6-8 line of code. When I comment one 'if' block of code (randomly chosen) the code running fantastically.... below is my 'if' block of code...

  else if (selectedIndex=="Sectoral Leverage Ratio"){
        ## Calculated number of row of the matrix ##
        rowNum <- selectedMonth[2] - selectedMonth[1] + 1

        ## Filter data based on criteria ##
        filteredData <- subset(rawData,Year %in% selectedYear & Month %in% selectedMonth[1]:selectedMonth[2] & Plant %in% selectedPlant)

        LeverageTable <- filteredData[,c('sch1ExpLeverage','sch2ExpLeverage','sch3ExpLeverage','sch4ExpLeverage','sch5ExpLeverage','sch7ExpLeverage','sch10ExpLeverage','sch11ExpLeverage')]
        LeverageSum <- apply(LeverageTable,2,sum)

        ExpTable <- filteredData[,c('sch1Exp','sch2Exp','sch3Exp','sch4Exp','sch5Exp','sch7Exp','sch10Exp','sch11Exp')]
        ExpSum <- apply(ExpTable,2,sum)


        LeverageRatio <- as.matrix(LeverageSum / ExpSum)
        AvgLeverageRatio <- as.matrix((LeverageSum / ExpSum)/rowNum)

        LeverageRatioTable <- cbind(LeverageRatio,AvgLeverageRatio)
        colnames(LeverageRatioTable) <- c('Leverage Ratio','Avg.Leverage Ratio')


        LeverageRatioTable <- data.frame(Sector=c('Health & Sant.','Edn. & Voc.','Social Welfare','Envt. Sust.','Hrtg & Arts','Sports','Rural Dvpt.','Admin Cost'),LeverageRatioTable)

        as.data.frame(LeverageRatioTable)

  }

All other 'if' blocks are almost similar (with some difference in calculation).

This is the problem of shiny-server; not the problem of 'R' itself.

If anybody wants to examin my code; I can share the full code.

Upvotes: 0

Marcel
Marcel

Reputation: 2794

According to ?name, you have to respect the fact that:

Names are limited to 10,000 bytes (and were to 256 bytes in versions of R before 2.13.0).

and the rule says in ?make.names:

A syntactically valid name consists of letters, numbers and the dot or underline characters and starts with a letter or the dot not followed by a number. Names such as ".2way" are not valid, and neither are the reserved words.

Upvotes: 0

Related Questions