FROM rocker/shiny:4.3.0

# Système
RUN apt-get update && apt-get install -y \
    curl \
    build-essential \
    libssl-dev \
    libxml2-dev \
    libcurl4-openssl-dev \
    git \
    && rm -rf /var/lib/apt/lists/*

# Rust pour CLARABEL
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# Packages R
RUN R -e "install.packages(c('shiny', 'shinythemes', 'shinyjs', 'DT', 'plotly', 'colourpicker', 'pracma', 'png', 'grid', 'remotes', 'devtools'))"
RUN R -e "install.packages(c('CVXR', 'osqp', 'ECOSolveR', 'scs'))"

# Installer BsplineQuantReg depuis GitHub
RUN R -e "devtools::packages('BsplineQuantReg')"

# Copier et installer BsplineQuantRegGui
COPY . /tmp/BsplineQuantRegGui
RUN R -e "devtools::install('/tmp/BsplineQuantRegGui', upgrade = 'never')"

# Nettoyer
RUN rm -rf /tmp/BsplineQuantRegGui

# Vérifier l'installation
RUN R -e "library(BsplineQuantRegGui); print(sessionInfo())"

# Port
EXPOSE 3838

# Lancer l'application
CMD ["R", "-e", "library(BsplineQuantRegGui); run_gui(host='0.0.0.0', port=3838)"]