Chapter 11. Bookmarking
By default, Shiny apps have one major drawback compared to most websites: you can’t bookmark the app to return to the same place in the future or share your work with someone else with a link in an email. That’s because, by default, Shiny does not expose the current state of the app in its URL. Fortunately, however, you can change this behavior with a little extra work, and this chapter will show you how. As usual, we begin by loading shiny:
library
(
shiny
)
Basic Idea
Let’s take a simple app that we want to make bookmarkable. This app draws Lissajous figures, which replicate the motion of a pendulum. This app can produce a variety of interesting patterns that you might want to share:
ui
<-
fluidPage
(
sidebarLayout
(
sidebarPanel
(
sliderInput
(
"omega"
,
"omega"
,
value
=
1
,
min
=
-2
,
max
=
2
,
step
=
0.01
),
sliderInput
(
"delta"
,
"delta"
,
value
=
1
,
min
=
0
,
max
=
2
,
step
=
0.01
),
sliderInput
(
"damping"
,
"damping"
,
value
=
1
,
min
=
0.9
,
max
=
1
,
step
=
0.001
),
numericInput
(
"length"
,
"length"
,
value
=
100
)
),
mainPanel
(
plotOutput
(
"fig"
)
)
)
)
server
<-
function
(
input
,
output
,
session
)
{
t
<-
reactive
(
seq
(
0
,
input
$
length
,
length.out
=
input
$
length
*
100
))
x
<-
reactive
(
sin
(
input
$
omega
*
t
()
+
input
$
delta
)
*
input
$
damping
^
t
())
y
<-
reactive
(
sin
(
t
())
*
input
$
damping
^
t
())
output
$
fig
<-
renderPlot
({
plot
(
x
(),
y
(),
axes
=
FALSE
,
xlab
=
""
,
ylab
=
""
,
type
=
"l"
,
lwd
=
2
)
},
res
=
96
)
}
Figure 11-1 shows the result.
Get Mastering Shiny now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.