R Shiny app from ArcGIS

3612
5
09-12-2019 04:20 AM
DavidMatthews3
New Contributor II

I have a toolbox containing an R script that creates a shiny app. When I run the script the app begins to render in a browser but then goes grey and I get an error saying 'c stack close to limit'

 The script works fine in rstudio and is based on this bridging-R-ArcGIS/interactiveKriging.R at master · BenGraeler/bridging-R-ArcGIS · GitHub 

Any ideas?

0 Kudos
5 Replies
by Anonymous User
Not applicable

It seems enough system memory is not allocated when app is called from the browser. RStudio has its own defaults for the memory limit which can be higher than the one allocated when the app is run in an another system. You can see how much memory R-Studio allocated with 

memory.limit()

You can update the amount of memory your operating system allocated by setting the parameter

setrlimit(2)

Here is more information about setting this limit.

0 Kudos
DavidMatthews3
New Contributor II

Thanks,Orhun

I'm on windows computer so setrlimit is not an option. 

Do you have any other ideas?

Cheers

0 Kudos
ShaunWalbridge
Esri Regular Contributor

How much memory is installed on the machine you're using for this analysis? Does it work with smaller inputs? Setting the stack size on Windows requires editing the executable file (its a compile-time option), which requires Visual Studio. Do you know where it gets in the execution prior to the stack size limit being hit?

Thanks,
Shaun

0 Kudos
DavidMatthews3
New Contributor II

Thanks for your help guys.

I've been doing some testing and seems to rendering the graph that is the problem. If I comment out line 40 ie. no graph displayed it works fine. But the script. including graph works in r studio (without tool_exec <- function...)

Here is the code I've been testing. Which the ArcGIS Toolbox script points to

################################################################################
### Interactive R and Arcgis Example
################################################################################
tool_exec <- function(in_params, out_params){
 
 arc.progress_label("Loading packages ...")
 arc.progress_pos(10)
 
 
 library(shiny)
 library(dplyr)

 
 ################################################################################
 ### Load Data 
 ################################################################################
 arc.progress_label("Loading data ...")
 arc.progress_pos(20)
 
 Year<-c(2000,2001,2002,2003,2000,2003,2000,2000,2005)
 Dwells<-c(50,20,25,26,27,300,100,80,100)
 
 df_test <- data.frame(Year,Dwells)

 ################################################################################
 ### Load App
 ################################################################################
 
 arc.progress_label("Starting App ...")
 arc.progress_pos(50)
 
 
 ui <- fluidPage(
 sidebarLayout(
 sidebarPanel(sliderInput("Explore_Years", 'Select years to explore',
 min=2000, max= 2005,value = c(2000,2005),sep='')),

 mainPanel(textOutput("text_out")
 , tableOutput("table_out")
 , plotOutput("graph_out") #####<<<< Works if comment this line out#######
 
 )
 )
 )

 server <- function(input, output) {
 
 Summary_test<-reactive({
 df_test%>%
 filter((Year >= input$Explore_Years[1]),
 (Year <= input$Explore_Years[2]) ) %>%
 group_by(Year)%>%
 summarize(Dwellings = sum(Dwells))
 })

 output$text_out <- renderText({paste ("You have selected minimum year ",input$Explore_Years[1])
 })
 
 output$table_out <- renderTable({Summary_test()
 })
 
 output$graph_out <- renderPlot({
 plot(Summary_test()$Year,Summary_test()$Dwellings)
 })
 
 }

 
 runApp(list(ui = ui, server = server))

}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
MarcoGalfetti
New Contributor

same errors with plotOutput and renderPlot... some solutions so far?
same app with textOutput and renderText work correctly

0 Kudos