forked from daattali/advanced-shiny
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
40 lines (34 loc) · 974 Bytes
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Dean Attali, October 2016
library(shiny)
library(shinyjs)
ui <- fluidPage(
shinyjs::useShinyjs(),
textInput("expr", label = "Enter an R expression",
value = "shinyjs::info('Hello!')"),
actionButton("run", "Run", class = "btn-success"),
shinyjs::hidden(
div(
id = "error",
style = "color: red; font-weight: bold;",
div("Oops, that resulted in an error! Try again."),
div("Error: ", br(),
span(id = "errorMsg", style = "margin-left: 10px;"))
)
)
)
server <- function(input, output, session) {
shinyEnv <- environment()
observeEvent(input$run, {
shinyjs::hide("error")
tryCatch(
isolate(
eval(parse(text = input$expr), envir = shinyEnv)
),
error = function(err) {
shinyjs::html("errorMsg", as.character(shiny::tags$i(err$message)))
shinyjs::show(id = "error", anim = TRUE, animType = "fade")
}
)
})
}
shinyApp(ui = ui, server = server)