REditorSupport / REditorSupport/vscode-R

Shiny app containing rintrojs code won't run in VSCode

Open
#1,574 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
1.2k
Forks
139
Avg merge
2h 46m
Merged PRs (30d)
5

Description

I have a shiny app which I originally developed using RStudio which I have been trying to run locally in VSCode (in both cases on a Windows 10 virtual machine). However, this doesn't work because of an error which only occurs when I try and run the app in VSCode, and not when I run exactly the same code in RStudio with the same version of R and the same package versions.

It appears to be being caused by the inclusion of code from the rintrojs library which includes some characters which VSCode thinks are invalid UTF-8 characters, triggering an error, but which RStudio does not have a problem with.

This is the error message I get in VSCode:
image

I have managed to create a minimally reproducible example of the problem I get in my app (I have highlighted the line which is causing the error):

library(shiny)
library(rintrojs)

# Define UI for application that draws a histogram
ui <- fluidPage(
  
  # Commenting the line below out stops the error from happening in VSCode, whereas including it is what triggers the error!
  rintrojs::introjsUI(),

    # Application title
    titlePanel("Old Faithful Geyser Data"),

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
        sidebarPanel(
            sliderInput("bins",
                        "Number of bins:",
                        min = 1,
                        max = 50,
                        value = 30)
        ),

        # Show a plot of the generated distribution
        mainPanel(
           plotOutput("distPlot")
        )
    )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

    output$distPlot <- renderPlot({
        # generate bins based on input$bins from ui.R
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)

        # draw the histogram with the specified number of bins
        hist(x, breaks = bins, col = 'darkgray', border = 'white',
             xlab = 'Waiting time to next eruption (in mins)',
             main = 'Histogram of waiting times')
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

I can run this code in RStudio with the line I have highlighted either included or not included and the app will load. However, if I leave that line in the code and try and run it in VSCode, then it will produce the error message I have shared above.

I have identified the characters which trigger the error message and they actually originate in the javascript package which that R function is providing a wrapper around, so I am not sure to what extent this is a R issue.

Environment (please complete the following information):

  • OS: Windows 10
  • VSCode Version: 1.90.1
  • R Version: 4.4.1
  • vscode-R version: 2.8.4
  • rintrojs Version: 0.3.2
  • shiny Version: 1.9.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal Shiny example and the rintrojs::introjsUI() entry point, then compare how vscode-R runs it with RStudio on the listed Windows, R, VSCode, and package versions. Reproduce the invalid UTF-8 error and trace the handling of the JavaScript characters; done when the example runs in VSCode with the rintrojs line included.

Written by the indexing model from the issue text.

Assessment

Tech stack
r, typescript, vscode
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.