-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathex5_sol.R
65 lines (55 loc) · 1.5 KB
/
ex5_sol.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
library(shiny)
library(magrittr)
library(purrr)
options(shiny.reactlog=TRUE)
zoom = FALSE
pigs_generator <- function(howmany){
tagList(1:howmany %>% map(function(x) icon("piggy-bank", lib = "glyphicon")))
}
ui <- fluidPage(
titlePanel("Hello Cardiff"),
sidebarLayout(
sidebarPanel(
uiOutput("sidebarui"),
actionButton("go_button", "Go!"),
textInput("name", "Give your name here"),
selectInput("column", "Select column to plot", colnames(mtcars))
),
mainPanel(
div(style = "background: grey; color: white;",
tags$p("Here is where the action takes place")
),
tags$h3(textOutput("welcome_message")),
#' (part 1) place for plotOutput
plotOutput("myplot"),
#' (part 2) place for uiOutput "pigs"
uiOutput("pigs"),
tags$img(src="https://media.giphy.com/media/u47skfNmdGSM05XP5G/giphy.gif", width="200px")
)
)
)
server <- function(input, output) {
if (isTRUE(zoom))
output$sidebarui <- renderUI({
tags$h2("This is sidebar")
})
else
output$sidebarui <- renderUI({
tags$h4("This is sidebar")
})
observeEvent(input$go_button, {
print("Go")
#' (part 2) add code for rendering pigs
output$pigs <- renderUI({
pigs_generator(input$go_button)
})
})
output$welcome_message <- renderText({
paste("Welcome", input$name)
})
#' (part 1) place for renderPlot
output$myplot <- renderPlot({
plot(mtcars[[input$column]]^2)
})
}
shinyApp(ui = ui, server = server)