-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tutorial data, Apps examples and codes
- Loading branch information
Showing
9 changed files
with
7,268 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
library(shiny) | ||
library(tidyverse) | ||
|
||
# ---------------------------------- | ||
# ---------------------------------- | ||
# ---------------------------------- | ||
# UI | ||
# ---------------------------------- | ||
# ---------------------------------- | ||
# ---------------------------------- | ||
|
||
ui <- fluidPage( | ||
headerPanel('Iris dataset'), | ||
sidebarPanel( | ||
selectInput('spec', 'Iris species', | ||
c("Setosa" = "setosa", | ||
"Versicolor" = "versicolor", | ||
"Virginica" = "virginica"), | ||
multiple= TRUE, | ||
selected = "setosa"), | ||
), | ||
mainPanel( | ||
plotOutput('plot_iris') | ||
) | ||
) | ||
|
||
|
||
# ---------------------------------- | ||
# ---------------------------------- | ||
# ---------------------------------- | ||
# SERVER SIDE | ||
# ---------------------------------- | ||
# ---------------------------------- | ||
|
||
server <- function(input, output) { | ||
|
||
output$plot_iris <- renderPlot({ | ||
iris_plot <- iris %>% filter(Species %in% input$spec) | ||
iris_plot %>% ggplot(aes(x=Petal.Length, Petal.Width, color=Species)) + | ||
geom_point()+ | ||
ggtitle("Edgar Anderson's Iris Data") + | ||
ylab("petal length")+ | ||
xlab("petal width")+ | ||
theme_minimal(base_size = 13) | ||
}) | ||
|
||
} | ||
|
||
|
||
# ---------------------------------- | ||
# ---------------------------------- | ||
# ---------------------------------- | ||
# App declaration | ||
# ---------------------------------- | ||
# ---------------------------------- | ||
shinyApp(ui = ui, server = server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
library(shiny) | ||
library(tidyverse) | ||
|
||
# load ramen Ratings dataset | ||
ramen_ratings <- readr::read_csv("ramen_dataset.csv") | ||
|
||
# get list of countries in dataset | ||
country_list<- ramen_ratings %>% select(country) %>% unique() | ||
|
||
# UI | ||
ui <- fluidPage( | ||
# ---------------------------------- | ||
h1("Best Ramens in the world", align = "center"), | ||
p("Explore the best ramens in the world, recommended by the users themselves! In this tab, you can | ||
select your favorite ramen style and the country of fabrication. The table below display the best three | ||
ramens for this selection!"), | ||
HTML('<center><img src="1200px-Shoyu_Ramen.jpg" width="100%"></center>'), | ||
HTML('<br/>'), | ||
# ---------------------------------- | ||
sidebarLayout(fluid=TRUE, | ||
sidebarPanel( | ||
selectInput("style", label="Select the ramen style:", | ||
c("Pack","Bowl","Cup" ), | ||
selected = "Cup", | ||
multiple= TRUE), | ||
|
||
selectInput("country", label="Select the country of fabrication:", | ||
country_list, | ||
selected = "Japan", | ||
multiple= FALSE), | ||
|
||
radioButtons("pType", label="Choose View:", | ||
list("Barchart", "Boxplot")) | ||
|
||
), | ||
mainPanel( | ||
h3(textOutput("toptitle"), align = "left"), | ||
tableOutput("top3"), | ||
conditionalPanel('input.pType=="Barchart"', plotOutput("barplot")), | ||
conditionalPanel('input.pType=="Boxplot"',plotOutput("boxplot")), | ||
), # end main panel | ||
), | ||
# ---------------------------------- | ||
includeHTML("footer.html"), | ||
) # end NavPage panel | ||
|
||
|
||
# ---------------------------------- | ||
# ---------------------------------- | ||
# ---------------------------------- | ||
# SERVER SIDE | ||
# ---------------------------------- | ||
# ---------------------------------- | ||
|
||
server <- function(input, output) { | ||
|
||
# Title main area | ||
# ---------------------------------- | ||
output$toptitle <- renderText({ | ||
paste("Best ramens in ", input$country) | ||
}) | ||
|
||
# ---------------------------------- | ||
# Reactive elements | ||
display_dataset <- reactive({ | ||
ramen_ratings %>% filter(style %in% input$style & country == input$country) | ||
}) | ||
|
||
# ---------------------------------- | ||
# Table output | ||
output$top3 <- renderTable({ | ||
display_dataset() %>% arrange(desc(stars)) %>% slice(1:3) %>% select(-continent, -review_number) | ||
}) | ||
|
||
# ---------------------------------- | ||
# Plot outputs | ||
output$barplot <- renderPlot({ | ||
display_dataset() %>% ggplot(aes(x=stars, fill=style)) + | ||
geom_histogram(color="black",binwidth = 1)+ | ||
scale_x_continuous(breaks = c(0, 1, 2, 3, 4, 5), limits = c(-1,6))+ | ||
ggtitle("Ramens Ratings") + | ||
ylab("Number of Ramens")+ | ||
xlab("Average Ratings")+ | ||
theme_minimal(base_size = 13) | ||
}) | ||
|
||
output$boxplot <- renderPlot({ | ||
display_dataset() %>% ggplot(aes(x=style, y=stars, color=style)) + | ||
geom_boxplot() + | ||
ggtitle("Ramens Ratings") + | ||
ylab("Average Ratings") + | ||
xlab("Style of Ramen") + | ||
theme_minimal(base_size = 13) | ||
}) | ||
|
||
} | ||
|
||
shinyApp(server = server, ui = ui) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<hr> | ||
|
||
<div class="container"> | ||
|
||
<!-- FOOTER --> | ||
<footer> | ||
<p class="pull-right"></p> | ||
<p>Data Science Group—Quadram Institute</p> | ||
<p>Intro to Shiny app development —Workshop</p> | ||
<p>Code available in <a href="https://github.com/quadram-institute-bioscience/datasciencegroup">Github</a></p> | ||
</footer> | ||
|
||
</div> |
Oops, something went wrong.