-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.R
105 lines (95 loc) · 2.07 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# This app demonstrates some of the functionality of this package.
# It will be updated as part of #49 to show more use cases.
# See ?shiny::loadSupport
options(shiny.autoload.r = FALSE)
pkgload::load_all(
export_all = FALSE,
helpers = FALSE,
attach_testthat = FALSE,
quiet = TRUE
)
# A simple-ish UI that demonstrates cookies functionality.
ui <- shiny::fluidPage(
title = "cookies package demo",
shiny::fluidRow(
shiny::column(
4,
shiny::textInput(
"user_name",
"What is your name?"
)
),
),
shiny::fluidRow(
shiny::column(
4,
shiny::actionButton(
"save_cookie",
"Save Cookie"
),
shiny::actionButton(
"delete_cookie",
"Delete Cookie"
)
)
),
shiny::fluidRow(
shiny::column(
4,
shiny::br(),
shiny::textOutput("greeting")
)
),
shiny::fluidRow(
shiny::column(
4,
shiny::textOutput("cookie_value")
)
)
)
# {cookies} makes it easy to add the necessary JavaScript.
ui <- add_cookie_handlers(ui)
server <- function(input, output, session) {
shiny::observe(
{
shiny::req(get_cookie("cookies_demo_name"))
shiny::updateTextInput(
session,
inputId = "user_name",
value = get_cookie("cookies_demo_name")
)
}
)
shiny::observeEvent(
input$save_cookie,
{
message("Saving cookie.")
set_cookie("cookies_demo_name", input$user_name)
}
)
shiny::observeEvent(
input$delete_cookie,
{
message("Deleting cookie.")
remove_cookie("cookies_demo_name")
}
)
output$greeting <- shiny::renderText({
shiny::req(input$user_name)
glue::glue("Hello, {input$user_name}!")
})
output$cookie_value <- shiny::renderText({
if (is.null(get_cookie("cookies_demo_name"))) {
"The cookie is not set."
} else {
glue::glue(
"The cookie is set to {get_cookie('cookies_demo_name')}.",
"Reload the page to see that it's retained between sessions."
)
}
})
}
shiny::shinyApp(
ui = ui,
server = server
)