-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
111 lines (90 loc) · 6.38 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
106
107
108
109
110
111
library(dplyr)
library(shiny)
library(shinythemes)
library(shinyWidgets)
library(png)
ui <- fluidPage(theme = shinytheme ("readable"), #themeSelector(),
titlePanel(tags$h1(tags$b("Pizzapp")), windowTitle = "Pizzapp"),
setBackgroundImage(src = "fondo.png"),
tags$h3("Creada por ", tags$a("Daniel Redondo.", href = "http://www.danielredondo.com")),
tags$h4("Con tantas marcas, precios y tamaños, a veces es difícil decidir qué pizza comprar.
Esta aplicación para amantes de la pizza te ayudará a tomar la mejor decisión
mostrándote el precio por centímetro cuadrado de pizza."),
tags$i(tags$b("Disclaimer"), ": El creador de Pizzapp apoya fuertemente la pizza con piña."),
fluidRow(
column(8, ""),
column(4, checkboxInput("trespizzas", "Comparar 3 pizzas", FALSE, width = '400px'))
),
fluidRow(
column(4, h2("Pizza 1:"),
fluidRow(column(6, numericInput(inputId = "d1",
label = "Diámetro en cm:",
value = "25",
width = "100%"
)),
column(6,numericInput(inputId = "p1",
label = "Precio :",
value = "12"
))),
hr(),
uiOutput("img1")
),
column(4,
h2("Pizza 2:"),
fluidRow(column(6, numericInput(inputId = "d2",
label = "Diámetro en cm:",
value = "35",
width = "100%"
)),
column(6,numericInput(inputId = "p2",
label = "Precio :",
value = "17"
))),
hr(),
uiOutput("img2")
),
column(4,
conditionalPanel(condition = "input.trespizzas == true",
h2("Pizza 3:"),
fluidRow(column(6, numericInput(inputId = "d3",
label = "Diámetro en cm:",
value = "45",
width = "100%"
)),
column(6,numericInput(inputId = "p3",
label = "Precio :",
value = "25"
))),
hr(),
uiOutput("img3")
)
)
)
)
server <- function(input, output) {
output$img1 <- renderUI(tags$div(tags$img(src="pizza.png", width = paste0(100 * input$d1 / max(input$d1, input$d2, input$d3), "%")),
tags$h3(if(input$d1 > 0 & input$p1 > 0) {
# area
HTML(paste0(round(pi * (input$d1 / 2) ^ 2, 2), " cm", tags$sup(2), "<br><br>",
# Price/cm2
round(100 * input$p1 / (pi * (input$d1 / 2) ^ 2), 2), " céntimos/cm", tags$sup(2)))
}, style = "position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%);"),
style = "position: absolute; text-align:center; color: black; font-weight: bold; text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white;"))
output$img2 <- renderUI(tags$div(tags$img(src="pizza.png", width = paste0(100 * input$d2 / max(input$d1, input$d2, input$d3), "%")),
tags$h3(if(input$d2 > 0 & input$p2 > 0) {
# area
HTML(paste0(round(pi * (input$d2 / 2) ^ 2, 2), " cm", tags$sup(2), "<br><br>",
# Price/cm2
round(100 * input$p2 / (pi * (input$d2 / 2) ^ 2), 2), " céntimos/cm", tags$sup(2)))
}, style = "position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%);"),
style = "position: absolute; text-align:center; color: black; font-weight: bold; text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white;"))
output$img3 <- renderUI(tags$div(tags$img(src="pizza.png", width = paste0(100 * input$d3 / max(input$d1, input$d2, input$d3), "%")),
tags$h3(if(input$d3 > 0 & input$p3 > 0) {
# area
HTML(paste0(round(pi * (input$d3 / 2) ^ 2, 2), " cm", tags$sup(2), "<br><br>",
# Price/cm2
round(100 * input$p3 / (pi * (input$d3 / 2) ^ 2), 2), " céntimos/cm", tags$sup(2)))
}, style = "position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%);"),
style = "position: absolute; text-align:center; color: black; font-weight: bold; text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white;"))
}
shinyApp(ui = ui, server = server)