Tutorial examples not working

Hallo everyone,

I am new to this forum and would like to learn writing shiny UIs. So I have a weird problem and could not find any topic helping me out.

In order to get started, I went to the tutorial here (https://shiny.rstudio.com/tutorial/written-tutorial/lesson1/#Go%20Further) and followed the instructions. Unfortunately, I cannot replicate the very first examples provided with the package.

For example, if I try to do:

runExample("01_hello")

instead of a windows displaying a slidebar and a histogram, i only get a window with an input field (instead of the slider).

Also, the following Code results into the same:

library(shiny)

# Define UI for app that draws a histogram ----
ui <- fluidPage(
  
  # App title ----
  titlePanel("Hello World!"),
  # Sidebar layout with input and output definitions ----
  sidebarLayout(
    # Sidebar panel for inputs ----
    sidebarPanel(
      # Input: Slider for the number of bins ----
      sliderInput(inputId = "bins",
                  label = "Number of bins:",
                  min = 1,
                  max = 50,
                  value = 30)  
    ),
    # Main panel for displaying outputs ----
    mainPanel(
      # Output: Histogram ----
      plotOutput(outputId = "distPlot") 
    )
  )
)

# Define server logic required to draw a histogram ----
server <- function(input, output) {
  
  # Histogram of the Old Faithful Geyser Data ----
  # with requested number of bins
  # This expression that generates a histogram is wrapped in a call
  # to renderPlot to indicate that:
  #
  # 1. It is "reactive" and therefore should be automatically
  #    re-executed when inputs (input$bins) change
  # 2. Its output type is a plot
  output$distPlot <- renderPlot({
    
    x    <- faithful$waiting
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    
    hist(x, breaks = bins, col = "#75AADB", border = "white",
         xlab = "Waiting time to next eruption (in mins)",
         main = "Histogram of waiting times")  
  }) 
}
# Create Shiny app ----
shinyApp(ui = ui, server = server)

I clearly can see a sliderbar called in the script above, making this issue even more confusing. Can someone help me out?

sessioninfo():
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C LC_TIME=German_Germany.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] DT_0.7 shiny_1.3.2

loaded via a namespace (and not attached):
[1] htmlwidgets_1.3 compiler_3.5.1 magrittr_1.5 R6_2.3.0 promises_1.0.1 later_0.8.0
[7] htmltools_0.3.6 tools_3.5.1 yaml_2.2.0 Rcpp_0.12.19 crosstalk_1.0.0 digest_0.6.18
[13] xtable_1.8-3 httpuv_1.5.1 mime_0.6

1 Like

@Eike That is strange indeed! I'm not sure what exactly the issue is, but here are some questions to help investigate further:

  1. What happens when you click on "Open in Browser"? Does the app appear any different when viewing it in different browsers (e.g. IE, Firefox, Chrome, etc)?

  2. What version of RStudio are you using? You can determine this by running RStudio.Version()$version in the R console.

1 Like

I tried different browsers (Firefox, IE, Chrome) via "Run App" -> "External". The results is always exactly the same... I am using RStudio 1.1.463.

1 Like

@Eike From your screenshot, it appears that your browser has disabled JavaScript and CSS. For example, here is a screenshot of the app when I use the Firefox Developer Tools to disable JavaScript:

Disabling JavaScript converted the slider to a standard input box and removed the plot.

When I disable Javascript and all the CSS rules, it looks closer to what you have:

Thus I think there must be some issue with your setup. Are you running this code on your personal machine or on a server? Are you able to view other websites that heavily rely on JavaScript (e.g. Facebook)?

1 Like

Oh yeah, that does look like my outcome! I am using my own Laptop for everything and am able to view webpages like facebook without any problems. I checked for JavaScript being enabled on Firefox (it is), but I don´t know how to deal with these CSS rules you mentioned. So assuming the problem might be the CSS rules, how can I try to fix this?

Thank you for your help!

1 Like

@Eike To see if the CSS files are being properly loaded, please follow these steps:

  1. Start the Shiny app: shiny::runExample("01_hello")
  2. Open the Shiny app in Firefox
  3. Press F12 to open the Developer Tools
  4. Click on the "Network" tab
  5. You should see a list of files and their download status on the left (you may have to click "reload")
  6. You want to see a status of 200 or 304. 200 means a successful download. 304 means successfully loaded from the cache (i.e. it was previously downloaded successfully). 404 is bad. This means it wasn't downloaded.

Here is what I see when I run the app. Note that all the JavaScript and CSS files have a status of 200. The only one that failed with 404 was an icon file.

Another useful tab is the "Style Editor". You can see all the CSS files that are being applied to the page, and you can also directly edit the CSS to see how it affects the styling.

1 Like

Looks like we are getting closer to the solution! It seems that neither CSS nor Java files were downloaded:

Do you have any suggestions on how to properly download/active the files?

Thanks again!

1 Like

@Eike Agreed! We've identified the main issue, but now how to solve it. Here are some ideas:

  1. Does your internet connection use a proxy? From this SO question, proxies can cause the type of problem you are seeing.

  2. What happens if you knit a standard R Markdown file? Or even better, a bookdown book? Do these render correctly in your browser? You can test with bookdown-demo.

  3. Can you see if you are able to download the Bootstrap files manually from within R by running the following:

download.file(url = "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css",
              destfile = tempfile())
download.file(url = "https://code.jquery.com/jquery-3.3.1.slim.min.js",
              destfile = tempfile())
download.file(url = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js",
              destfile = tempfile())
download.file(url = "https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js",
              destfile = tempfile())
1 Like

Thanks again, I really appreciated your fast help! Okay, let´s see...

  1. I followed your link and this lead mit to Shiny v1.3 known regressions and serious issues where i tried solution 1) by simply executing remotes::install_github("rstudio/httpuv") in the console. But i didn´t change anything. Neither did selecting the "No proxy" option of my browser (firefox).

  2. Knitting a Markdown like here https://rmarkdown.rstudio.com/articles_intro.html worked just fine. I got rendered successfully in the browser. Same goes for the bookdown demo, you provided. Even though trying the "Build Book" Button form the "Build" Tab gives out the error Failed to compile bookdown-demo.tex. [...] Exited with status 1. ...but I assume that this has no relation to my actual problem?

  3. Copy-pasting these commands seemed to work just fine. I got no errors.

So I guess, everything worked but didn´t point out the source of my problem? I am not 100% sure about the bookdown thing, since I´m not familiar with it (neither am I with proxy things and stuff like that, as you might have guessed by now). But like I said, it seemed to work just fine.

Sooo yeah... any ideas?

1 Like

Do you have an antivirus system installed? I wonder if there's something intercepting the JS and CSS files.

If you click on one of those 404s that you showed in your screenshot, it should show some more details on the headers sent/received. It'd be interesting to see those so we can see if the request is making it to the real Shiny process.

On the latest version of httpuv (which it looks like you already have), you can run httpuv:::logLevel("DEBUG") which will show some detail from Shiny's perspective as requests come and go. That might also be interesting to look at.

2 Likes

One other idea -- which I'm horrified to even suggest -- is that the non-ASCII characters in the path might be causing problems on Windows.

If you had a way to try from a directory that had only ASCII characters, that might be an interesting test.

2 Likes

It looks like @trestletech is right: the problem is that it's having trouble serving up files due to the the non-ASCII character in the path where Shiny is installed. I've filed an issue here: https://github.com/rstudio/httpuv/issues/224

We'll try to get a fix in right away. In the meantime, if you know how to change your .libPaths(), you can add a path with only ASCII characters to the beginning.

2 Likes

Wow... sometimes, the simple solution is the right one. I reinstalled shiny in the common library (and not the personal one, containing my name with the non-ASCII character) and everything got rendered fine right away. No more 404s in the Developer Tools (now mostly 200s and 304s).

Problem solved! Thank you guys very much for helping!

1 Like

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

2 Likes

We have a potential fix for the issue here: https://github.com/rstudio/httpuv/pull/227

You can install it by first restarting R, then running:

devtools::install_github("rstudio/httpuv@wch-fix-windows-staticfile")
2 Likes

I restarted RStudio and tried to run the command, but unfortunately got an error. ErrorGit

1 Like

@Eike The Pull Request was merged and that branch was deleted. Now you can obtain that recent update by installing directly from the master branch of GitHub with:

devtools::install_github("rstudio/httpuv")
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.