Runtime error - Why and how to solve?

Hello,

I have a personal project for which I would like to use this a tool called PhacochR.

I managed to run and test it locally with R, but I need this to be available even when my laptop is closed.
For this, I wanted to use a HuggingFace space and I made this space : ApiPhacochR - a Hugging Face Space by totonicknick

I started up a blank docker space with the free tier resources and added 2 files (after several iterations with gemini 2.5 to try to resolve my issues, both can be found in https://huggingface.co/spaces/totonicknick/apiPhacochR/resolve/main) :

  1. Dockerfile
  2. api.R

After several iterations with the help of gemini-2.5, I still can’t make it work due to a runtime error.

This is the explanation according to Gemini-2.5-Pro, but doing a factory reset did not help one bit and I’m too much of a beginner to know what to do next.

The launch is timing out because of a subtle configuration issue.

Your build logs show that even with the correct Dockerfile, the data for the phacochr package is being installed in the wrong place. This means that when the application tries to run, it can’t find its necessary files and eventually times out.


The Problem in the Logs

The key piece of evidence is this line from your build log:

✔ CrĂ©ation du dossier : ~/.local/share/phacochr/data_phacochr

This line confirms that the phacochr package is ignoring the ENV PHACOCHR_DATA_DIR variable and installing data to its default user directory. The application then fails at runtime because it can’t find this data.

This situation is unusual and suggests that the build environment might be ignoring the ENV variable or there’s a caching issue.


The Solution

The most robust solution is to force a clean rebuild of your application. You can do this by using the “Factory reboot” option in your Hugging Face Space settings. This will clear any persistent storage or cache and force the build process to run from a completely clean state.

Here’s what to do:

  1. Go to the Settings tab of your Space.

  2. Scroll down to the bottom of the page.

  3. Click the “Factory reboot” button. This will trigger a completely new build.

After the reboot, monitor the new build logs. You should see the installation path change to /opt/phacochr/data. If it does, your application will have the data it needs and should start correctly.

1 Like

I couldn’t add more links in the post because I’m a new user.

This is the link to the PhacochR geocoder: Geocoder for Belgium - Geocodeur pour la Belgique ‱ phacochr

Here is the part of the log that seems most relevant to me

<details>
<summary>log</summary>
<pre>
* checking for file ‘/tmp/Rtmpq1OeoD/remotes12c0544d90cf/phacochr-phacochr-1ae5dc2/DESCRIPTION’ ... OK
* preparing ‘phacochr’:
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘phacochr_0.9.1.14.tar.gz’
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
* installing *source* package ‘phacochr’ ...
** this is package ‘phacochr’ version ‘0.9.1.14’
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (phacochr)
> 
DONE 56.9s
--> RUN R -e 'phacochr::phaco_setup_data()'
R version 4.5.1 (2025-06-13) -- "Great Square Root"
Copyright (C) 2025 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
  Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> phacochr::phaco_setup_data()
 -- Chargement des données pour PhacochR --
✔ CrĂ©ation du dossier : ~/.local/share/phacochr/data_phacochr
⧗ TĂ©lĂ©chargement des donnĂ©es ...
trying URL 'https://github.com/phacochr/phacochr_data/raw/main/data_phacochr/phacochr_data_best.zip'
Content type 'application/zip' length 42898771 bytes (40.9 MB)
==================================================
downloaded 40.9 MB
trying URL 'https://github.com/phacochr/phacochr_data/raw/main/data_phacochr/phacochr_data_statbel_urbis.zip'
Content type 'application/zip' length 51980195 bytes (49.6 MB)
==================================================
downloaded 49.6 MB
✔ TĂ©lĂ©chargement des donnĂ©es
⧗ DĂ©compression des donnĂ©es
✔ DĂ©compression des donnĂ©es
✔ Importation des donnĂ©es OK: PhacochR prĂȘt Ă  gĂ©ocoder.> 
DONE 5.4s
--> COPY api.R /api.R
DONE 0.0s
--> Pushing image
DONE 5.4s
--> Exporting cache
DONE 0.1s
</pre>
</details>
1 Like

If you want to use a port other than 7860, you need to specify it in README.md. Otherwise, the port won’t open and the process will keep waiting indefinitely


---
sdk: docker
app_port: 8000
startup_duration_timeout: 1h   # optional
---

Thanks, I’ll test that today!

1 Like