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)
Related Topics
How to Change the Default Directory in Rstudio (Or R)
R Group By, Counting Non-Na Values
Converting to Date in a Character Column That Contains Two Date Formats
How to Capture the Output of System()
Large Integers in Data.Table. Grouping Results Different in 1.9.2 Compared to 1.8.10
R: Strptime() and Is.Na () Unexpected Results
R // Sum by Based on Date Range
Calculate Percentage for Each Time Series Observations Per Group in R
Generally Disable Dimension Dropping for Matrices
How to Minimize Size of Object of Class "Lm" Without Compromising It Being Passed to Predict()
Accessing Y Columns with Duplicated Names in J of X[Y, J] Merges
Error in Bind_Rows_(X, .Id):Argument 1 Must Have Names
Why Does Subsetting a Column from a Data Frame VS. a Tibble Give Different Results
How to Preserve Continuous (1,2,3,...N) Ranking Notation When Ranking in R
Text Mining in R | Memory Management
Lm(): What Is Qraux Returned by Qr Decomposition in Linpack/Lapack