VCR
VCR

Reputation: 21

Shiny app error sourcing debug

I'm loading a shiny app built to render a risk with new input variables from a logistic regression model built on a csv file. Any ideas for debug? The error message when loading the app is as follows:

ERROR: Error sourcing C:\Users\Vincent\AppData\Local\Temp\RtmpATsPEW\filef604271fa   with such message on the R studio console : 
Warning in checkEncoding(file) :
  The input file C:/Users/Vincent/Documents/R Apprentissage/Applications Shiny/Prediction insuffisance renale aigue chez les ileostomises.R/Prediction IRA chez ileostomises.R does not seem to be encoded in UTF8
Warning: invalid input found on input connection 'C:/Users/Vincent/Documents/R Apprentissage/Applications Shiny/Prediction insuffisance renale aigue chez les ileostomises.R/Prediction IRA chez ileostomises.R'
Error in parse(file, keep.source = FALSE, srcfile = src, encoding = enc) : 
  C:/Users/Vincent/Documents/R Apprentissage/Applications Shiny/Prediction insuffisance renale aigue chez les ileostomises.R/Pr:5:14: unexpected INCOMPLETE_STRING
4: ui <- fluidPage(
5:   titlePanel("Pr
                ^
Warning: Error in sourceUTF8: Error sourcing C:\Users\Vincent\AppData\Local\Temp\RtmpATsPEW\filef604271fa
Stack trace (innermost first):
    1: runApp
Error : Error sourcing C:\Users\Vincent\AppData\Local\Temp\RtmpATsPEW\filef604271fa
 ui <- fluidPage(
  titlePanel("Prédiction d'insuffisance rénale aiguë chez les iléostomisés"),
   sidebarLayout(
     sidebarPanel(

  checkboxGroupInput("checkboxGroup1", "Cancer colorectal", 
                     choices = list("Absente" = 1, 
                                    "Présente" = 2),
                     selected = 1),

  checkboxGroupInput("checkboxGroup2", "Maladie cardiovasculaire", 
                     choices = list("Absente" = 1, 
                                    "Présente" = 2),
                     selected = 1),

  checkboxGroupInput("checkboxGroup3", "Maladie thrombo-embolique veineuse", 
                     choices = list("Absente" = 1, 
                                    "Présente" = 2),
                     selected = 1),

  checkboxGroupInput("checkboxGroup4","Démence", 
                     choices = list("Absente" = 1, 
                                    "Présente" = 2),
                     selected = 1),

  checkboxGroupInput("checkboxGroup5","Résection rectale antérieure", 
                     choices = list("Absente" = 1, 
                                    "Présente" = 2),
                     selected = 1),

  checkboxGroupInput("checkboxGroup6","Hémicolectomie gauche", 
                     choices = list("Absente" = 1, 
                                    "Présente" = 2),
                     selected = 1),

  checkboxGroupInput("checkboxGroup7","Chimiothérapie per iléostomie", 
                     choices = list("Absente" = 1, 
                                    "Présente" = 2),
                     selected = 1),

  checkboxGroupInput("checkboxGroup8","Iléostomie à haut débit", 
                     choices = list("Absente" = 1, 
                                    "Présente" = 2),
                     selected = 1),

  checkboxGroupInput("checkboxGroup9","Deshydratation", 
                     choices = list("Absente" = 1, 
                                    "Présente" = 2),
                     selected = 1),

  sliderInput("slider1","Créatininémie pré-opératoire", min = 20, max = 400, value = 100),

  sliderInput("slider2", "Age", min = 0, max = 100, value = 50)
),

  mainPanel(
tabPanel("Probabilité de développer une insuffisance rénale aiguë",textOutput("pred1")))
 ))



data_app <- read.csv("./data/DatasetpourShiny", header = TRUE, sep = ";", quote = "\"", dec = ",", fill = TRUE)
server <- function(input, output) {

  model1 <- glm(Augmentation.creat.26.umolL.en.48H ~ 
              Cancer.colique.ou.rectal + 
              ATCD.maladie.cardiovasculaire +
              ATCD.MTEV +
              Demences +
              Resection.anterieure.rectum +
              Type.colectomie_2 +
              Chimio.porteur.ileostomie +
              Stomie.a.haut.debit +
              Deshydratation.post.op +
              Creatininemie.pre.operatoire +
              Age, family= "binomial", data = data_app)

  model1pred <- reactive ({
Cancer.colique.ou.rectalInput <- input$checkboxGroup1  
ATCD.maladie.cardiovasculaireInput <- input$checkboxGroup2
ATCD.MTEVInput <- input$checkboxGroup3
DemencesInput <- input$checkboxGroup4
Resection.anterieure.rectumInput <- input$checkboxGroup5
Type.colectomie_2Input <- input$checkboxGroup6
Chimio.porteur.ileostomieInput <- input$checkboxGroup7
Stomie.a.haut.debitInput <- input$checkboxGroup8
Deshydratation.post.opInput <- input$checkboxGroup9
Creatininemie.pre.operatoireInput <- input$slider1
AgeInput <- input$slider2

    predict(model1, 
        newdata = data.frame(
          Cancer.colique.ou.rectal =  Cancer.colique.ou.rectalInput,
          ATCD.maladie.cardiovasculaire = ATCD.maladie.cardiovasculaireInput,
          ATCD.MTEV = ATCD.MTEVInput,
          Demences = DemencesInput,
          Resection.anterieure.rectum = Resection.anterieure.rectumInput,
          Type.colectomie_2 = Type.colectomie_2Input,
          Chimio.porteur.ileostomie  =  Chimio.porteur.ileostomieInput,
          Stomie.a.haut.debit = Stomie.a.haut.debitInput,
          Deshydratation.post.op = Deshydratation.post.opInput,
          Creatininemie.pre.operatoire = Creatininemie.pre.operatoireInput,
          Age = AgeInput
        ))
  })
  output$pred1 <- rendertext({
exp(model1pred())/(1+exp(model1pred()))*100
  })
 }



shinyApp(ui = ui, server = server)

Upvotes: 2

Views: 11074

Answers (3)

Katherine Li
Katherine Li

Reputation: 61

I also confronted the same error. I realized that it happened because there is an unmatched opening bracket. You can go to "Code" on the top bar menu and select "Show Diagnostics(Project)" to find out in which line is there a opening bracket. Hope this helps.

Upvotes: 1

Vijay Patel
Vijay Patel

Reputation: 41

On Rstudio :

  1. Go to file in top left corner.

  2. Select save with encoding

  3. select UTF-8

Do this for all R scripts (server.R/app.R)

This worked for me.

Upvotes: 4

derpylz
derpylz

Reputation: 41

It seems like you have a problem with the encoding of the special characters in your UI. Make sure you save your file with utf8 encoding. Have a look here: Shiny Documentation on special characters

I copied your code into a file in RStudio and saved it with UTF-8 encoding. It was working that way.

Hope that helps.

Upvotes: 4

Related Questions