Spaces:
Sleeping
Sleeping
Commit
·
f89a25e
0
Parent(s):
Initial commit
Browse files- .gitignore +4 -0
- app.R +41 -0
- examples.Rproj +13 -0
.gitignore
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.Rproj.user
|
2 |
+
.Rhistory
|
3 |
+
.RData
|
4 |
+
.Ruserdata
|
app.R
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
library(shiny)
|
2 |
+
library(bslib)
|
3 |
+
library(dplyr)
|
4 |
+
library(ggplot2)
|
5 |
+
|
6 |
+
df <- palmerpenguins::penguins
|
7 |
+
|
8 |
+
choices <- c(
|
9 |
+
"Bill length (mm)" = "bill_length_mm",
|
10 |
+
"Bill depth (mm)" = "bill_depth_mm",
|
11 |
+
"Flipper length (mm)" = "flipper_length_mm",
|
12 |
+
"Body mass (g)" = "body_mass_g"
|
13 |
+
)
|
14 |
+
|
15 |
+
ui <- page_fillable(theme = bs_theme(bootswatch = "minty"),
|
16 |
+
layout_sidebar(fillable = TRUE,
|
17 |
+
sidebar(
|
18 |
+
selectInput("xvar", "X variable", choices, selected = choices[[1]]),
|
19 |
+
selectInput("yvar", "Y variable", choices, selected = choices[[2]]),
|
20 |
+
checkboxInput("smooth", "Add smoother"),
|
21 |
+
checkboxInput("species", "By species", TRUE)
|
22 |
+
),
|
23 |
+
plotOutput("scatter")
|
24 |
+
)
|
25 |
+
)
|
26 |
+
|
27 |
+
server <- function(input, output, session) {
|
28 |
+
subsetted <- reactive({
|
29 |
+
df[, unique(c(input$xvar, input$yvar, "species"))]
|
30 |
+
})
|
31 |
+
|
32 |
+
output$scatter <- renderPlot({
|
33 |
+
ggplot(subsetted(), aes_string(input$xvar, input$yvar, color = if (input$species) "species")) +
|
34 |
+
geom_point() +
|
35 |
+
xlab(names(choices)[choices == input$xvar]) +
|
36 |
+
ylab(names(choices)[choices == input$yvar]) +
|
37 |
+
if (input$smooth) geom_smooth()
|
38 |
+
}, res = 100)
|
39 |
+
}
|
40 |
+
|
41 |
+
shinyApp(ui, server)
|
examples.Rproj
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Version: 1.0
|
2 |
+
|
3 |
+
RestoreWorkspace: Default
|
4 |
+
SaveWorkspace: Default
|
5 |
+
AlwaysSaveHistory: Default
|
6 |
+
|
7 |
+
EnableCodeIndexing: Yes
|
8 |
+
UseSpacesForTab: Yes
|
9 |
+
NumSpacesForTab: 2
|
10 |
+
Encoding: UTF-8
|
11 |
+
|
12 |
+
RnwWeave: Sweave
|
13 |
+
LaTeX: pdfLaTeX
|