Shiny Tutorial Error in R

Shiny tutorial lesson 6: getting error

Found the answer in other thread in stack-overflow:

Quantmod Error 'cannot open URL'

The code that should be used to run the app for lesson 6 is:

library(shiny)
options(download.file.method="libcurl")#This fixed the error
runApp("stockVis")

Automatically test if shiny crashes and retrieve error?

To test if shiny app crashes on launch

testthat::test_that("server launches",{
local_edition(3)
skip_on_cran()
skip_on_travis()
skip_on_appveyor()
app <- shinytest::ShinyDriver$new(here::here()) #open shiny app

a <- data.frame(app$getDebugLog()) #check debug log for error

a <- a %>%
filter(!grepl('Warning: ', message)) %>% filter(level == "ERROR")

if (length(grep("Error in", a)) == 0)
alive = TRUE
else
alive = FALSE
expect_true(alive) })

Shiny (Rstudio) apps not working

After updating Rstudio to the newest version redo the install.packages("shiny") and library("shiny"). Once you do this it should eliminate the need to manually do the runApp code and a button should appear were the run button usually is that says run app. before you can click run app though you have to set your working directory to the location were you have saved your server.R and ui.R by going to session -> set working directory -> choose directory. chose the folder location then click run app.

Edit: there should be no need for you to run that code from GitHub

Avoid closing Shiny browser when an error occurs

You could catch the error with trycatch and display it with showNotification. I've illustrated this with the Old Faithful Geyser shiny example and added in the trycatch so the app does not crash:

library(shiny)

ui <- fluidPage(

titlePanel("Old Faithful Geyser Data"),

sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),

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

server <- function(input, output) {

###
#CATCHING THE ERROR IN A NOTIFICATION
###
tryCatch({
x1 <- DBI::dbGetQuery(con,
statement = glue_sql("SELECT DISTINCT COLUMN1 FROM TABLE1", .con = con))
},
warning = function(warn){
showNotification(paste0(warn), type = 'warning')
},
error = function(err){
showNotification(paste0(err), type = 'err')
})

output$distPlot <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)

hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}

shinyApp(ui = ui, server = server)

Sample Image
Sample Image



Related Topics



Leave a reply



Submit