Skip to content

Commit

Permalink
Tutorial data and codes
Browse files Browse the repository at this point in the history
Adding tutorial data, Apps examples and codes
  • Loading branch information
aponsero committed Apr 15, 2024
1 parent 181465a commit 1481d81
Show file tree
Hide file tree
Showing 9 changed files with 7,268 additions and 0 deletions.
56 changes: 56 additions & 0 deletions 6_Intro_ShinyApps/Apps/Iris_app/App.R
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)
98 changes: 98 additions & 0 deletions 6_Intro_ShinyApps/Apps/Ramen_app/App.R
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)
13 changes: 13 additions & 0 deletions 6_Intro_ShinyApps/Apps/Ramen_app/footer.html
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&mdash;Quadram Institute</p>
<p>Intro to Shiny app development &mdash;Workshop</p>
<p>Code available in <a href="https://github.com/quadram-institute-bioscience/datasciencegroup">Github</a></p>
</footer>

</div>
Loading

0 comments on commit 1481d81

Please sign in to comment.