Running Shiny App locally in Microsoft browsers gives browser errors

Hello,

I'm new to Shiny, and having some trouble with odd, seemingly random errors. I have reduced my app down to a very basic form, given below. The issue I'm having is that when launching the app through RStudio, the plot will not load. In the browser console I can see that this is due to Javascript errors like this:

This never occurs in Chrome, but it will happen in Internet Explorer and Edge. In my full app the error in the browser console is not always the same--often it doesn't happen at all and the page loads just fine, but other times the error would reference crosstalk or DT (these are used in my full app). Often the plotly plot would load, but the DT table would not, or vice versa. It seems to happen independently on each page and with each element on the page; sometimes the first page would load fine, but then I would switch pages and an element would fail to load (again, with a browser console error). There is never any output in the R console.

In the pared down example below, I have been able to consistently reproduce the error through these steps:

  1. It only happens in Internet Explorer and Edge (works in Chrome), so one of these must be the default browser
  2. Restart the R session in RStudio
  3. Run the app with the "Run External" option in RStudio

This results in the plot failing to load and the error message in the browser console. It only occurs the first time after the R session has been restarted--any further attempts to run the App within the same R session will typically work flawlessly.

Any help would be much appreciated. I've been tearing my hair out over this one.

library(shiny)
library(plotly)


tb <- tibble(
  x = rnorm(100, mean = 10),
  y = rnorm(100, mean = 20),
  z = rnorm(100, mean = 30)
)


ui <- fluidPage(

  titlePanel("Demo"),
  
  sidebarLayout(
    sidebarPanel(
      selectInput("x.axis", label = "X-Axis", choices = names(tb), selected = "x"),
      selectInput("y.axis", label = "Y-Axis", choices = names(tb), selected = "y")
    ),
  mainPanel(
      plotlyOutput("plot")
    )
  )
)

server <- function(input, output, session) {
  
  output$plot <- renderPlotly({
    
    inputs <- c(input$x.axis, input$y.axis)

    p <-
      plot_ly(data = tb,
              type = "scatter",
              mode = "markers")
    p <- add_trace(p,
                   x = as.formula(paste0("~`", input$x.axis, "`")),
                   y = as.formula(paste0("~`", input$y.axis, "`")))
  })
}

shinyApp(ui = ui, server = server)
1 Like

Hello,

Any update with this issue? Also currently experiencing the same problem with my large-scale shiny app. Also currently tearing my hair out over this one.

Thanks!

The problem is, that you are using periods in your inputId names, as mentioned here:

You are not recommended to use special JavaScript characters such as a period . in the input id's, but if you do use them anyway, for example, inputId = "foo.bar" , you will have to use input["foo.bar"] instead of input.foo.bar to read the input value.

The following should work (replaced x.axis with x_axis):

library(shiny)
library(plotly)
library(tibble)


tb <- tibble(
  x = rnorm(100, mean = 10),
  y = rnorm(100, mean = 20),
  z = rnorm(100, mean = 30)
)


ui <- fluidPage(
  
  titlePanel("Demo"),
  
  sidebarLayout(
    sidebarPanel(
      selectInput("x_axis", label = "X-Axis", choices = names(tb), selected = "x"),
      selectInput("y_axis", label = "Y-Axis", choices = names(tb), selected = "y")
    ),
    mainPanel(
      plotlyOutput("plot")
    )
  )
)

server <- function(input, output, session) {
  
  output$plot <- renderPlotly({
    
    inputs <- c(input$x_axis, input$y_axis)
    
    p <- plot_ly(data = tb,
              type = "scatter",
              mode = "markers")
    p <- add_trace(p,
                   x = ~ get(input$x_axis),
                   y = ~ get(input$y_axis)) %>%
      layout(xaxis = list(title = input$x_axis), yaxis = list(title = input$y_axis))
  })
}

shinyApp(ui = ui, server = server)

Thanks for the response, ismirsehregal.

Unfortunately that change did not resolve the issue on my computer. The problem still pops up intermittently.

Works for me using edge. :thinking:

Here's my most recent error in the Edge debug console using your code:

image

The really odd thing is that it does work flawlessly most of the time. The only way I can get it to consistently break is to restart the R session before launching the Shiny app. Maybe the error has something to do with loading the packages? (I'm really grasping at straws here.) Replacing plotly with ggplot2 fixes the issue, so it's something to do with plotly/crosstalk/htmlwidgets.

Update on this: My app is now running on a server and it works fine in all browsers. The issue remains when launching it locally on my PC in IE/Edge immediately after restarting R.