Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
gulinan committed Jan 9, 2022
1 parent 8a7ffeb commit 21ab2be
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 54 deletions.
Binary file modified .DS_Store
Binary file not shown.
48 changes: 48 additions & 0 deletions app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(

## Main header
tags$h1("My First Shiny App"),

tags$p(" I love data science."),

## Un-ordered list

tags$ul(
tags$li("Tidyverse"),
tags$li("Rvest"),
tags$li("Shiny")
),


## Tags can be nested.

tags$p(
"The link to the Shiny website is",
tags$a(href = "https://www.rstudio.com/shiny/", "rstudio.com/shiny."),
tags$strong("I strongly recommend that you take a look at it!")
),

## Some line break.
tags$br(),

## Include video.

tags$iframe(src="https://www.youtube.com/embed/xJALSnbBHhk", width="1000", height="500",
frameborder="0",
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"),

tags$br(),

tags$span(style="color:purple", "Have a good winter break!..")
)

# Define server logic required to draw a histogram
server <- function(input, output) {

}

# Run the application
shinyApp(ui = ui, server = server)
13 changes: 8 additions & 5 deletions countries-01/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ countries_data_2011 <- countries_data %>%
## UI ##########################################################################
ui <- fluidPage(

sidebarLayout(#position = "right",
sidebarLayout(#position = "right", #default widget position is left

## define inputs in sidebar -------------------------------
sidebarPanel(

## select variable for scatter plot x-axis --------------
## label: widget label.
##select variable widget for scatter plot x-axis --------------
#inputId: The input slot that will be used to access the value.
#label: Display label for the control, or NULL for no label.
#choices: List of values to select from. column names from the data set.
#selected: The initially selected value.
selectInput(inputId = "x_axis", label = "X axis",
choices = c("human_development_index", "corruption_perception_index",
"population", "life_exp", "gdp_per_capita"),
selected = "human_development_index"),

## select variable for scatter plot y-axis ---------------
##select variable widget for scatter plot y-axis --------------
selectInput(inputId = "y_axis", label = "Y axis",
choices = c("human_development_index", "corruption_perception_index",
"population", "life_exp", "gdp_per_capita"),
Expand All @@ -47,7 +50,7 @@ server <- function(input, output) {

## input and output are list-type objects. list elements will be named by me.
## create a scatter plot.
## output is a reserved word.
## input and output are reserved words.
## countries_scatter is given by me.
## input has two parts: x_axis and y_axis
## renderPlot({expr}): Renders a reactive plot that is suitable for assigning to an output plot.
Expand Down
1 change: 0 additions & 1 deletion countries-02/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ ui <- fluidPage(
sidebarPanel(

## select variable for scatter plot x-axis --------------
## label: widget label.
selectInput(inputId = "x_axis", label = "X axis",
choices = c("human_development_index", "corruption_perception_index",
"population", "life_exp", "gdp_per_capita"),
Expand Down
12 changes: 8 additions & 4 deletions countries-03/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ ui <- fluidPage(
sidebarPanel(

## select variable for scatter plot x-axis --------------
## label: widget label.
selectInput(inputId = "x_axis", label = "X axis",
choices = c("human_development_index", "corruption_perception_index",
"population", "life_exp", "gdp_per_capita"),
Expand All @@ -37,8 +36,13 @@ ui <- fluidPage(
selected = "population"),

## set transparency level for points in the scatter plot ----------------
sliderInput(inputId ="transvalue", label = "Transparency",
min = 0, max = 1, value = 0.8)
## inputId: The input slot that will be used to access the value.
## label: Display label for the control,
## min, max: The minimum and maximum values (inclusive) that can be selected.
## value:The initial value of the slider
sliderInput(inputId ="transvalue",
label = "Transparency",
min = 0, max = 1, value = 0.8)

),

Expand All @@ -58,7 +62,7 @@ server <- function(input, output) {
ggplot(data = countries_data_2011,
aes_string(x = input$x_axis, y = input$y_axis)) +
geom_point(aes_string(color="continent", size=input$size), alpha = input$transvalue) +
#note that i am directly changing the characteristics of point. it is out of aes().
#note that i am mapping the alpha size onto a variable. for that reason it is out of aes().
#i mean its value does not depend on a variable, that is why it is out of aes().
theme_minimal()
})
Expand Down
2 changes: 1 addition & 1 deletion countries-04/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ui <- fluidPage(
sidebarPanel(

## select variable for scatter plot x-axis --------------
## label: widget label.

selectInput(inputId = "x_axis", label = "X axis",
choices = c("human_development_index", "corruption_perception_index",
"population", "life_exp", "gdp_per_capita"),
Expand Down
5 changes: 4 additions & 1 deletion countries-05/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ui <- fluidPage(
sidebarPanel(

## select variable for scatter plot x-axis --------------
## label: widget label.

selectInput(inputId = "x_axis", label = "X axis",
choices = c("human_development_index", "corruption_perception_index",
"population", "life_exp", "gdp_per_capita"),
Expand All @@ -42,6 +42,9 @@ ui <- fluidPage(
min = 0, max = 1, value = 0.8),

## checkbox to show/hide data table -------------------
## inputId: The input slot that will be used to access the value.
## label: Display label for the control, or NULL for no label.
## value: Initial value (TRUE or FALSE).
checkboxInput(inputId = "show_table", label = "Show table",
value = TRUE)

Expand Down
15 changes: 8 additions & 7 deletions countries-06/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ui <- fluidPage(
sidebarPanel(

## select variable for scatter plot x-axis --------------
## label: widget label.

selectInput(inputId = "x_axis", label = "X axis",
choices = c("human_development_index", "corruption_perception_index",
"population", "life_exp", "gdp_per_capita"),
Expand Down Expand Up @@ -72,13 +72,14 @@ server <- function(input, output) {
#https://stackoverflow.com/questions/37663854/convert-ggplot-object-to-plotly-in-shiny-application
output$countries_scatter <- renderPlotly({

ggplotly(ggplot(data = countries_data_2011,
aes_string(x = input$x_axis, y = input$y_axis)) +
geom_point(aes_string(color="continent", size=input$size),
alpha = input$transvalue) +
theme_minimal())


p_scatter <- ggplot(data = countries_data_2011,
aes_string(x = input$x_axis, y = input$y_axis)) +
geom_point(aes_string(color="continent", size=input$size),
alpha = input$transvalue) +
theme_minimal()

ggplotly(p_scatter)

})

Expand Down
11 changes: 5 additions & 6 deletions countries-07/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
library(shiny)
library(tidyverse)
library(plotly)
library(DT)

## read data -------------------------------------------------------------------

Expand Down Expand Up @@ -59,7 +60,7 @@ ui <- fluidPage(

plotlyOutput(outputId = "countries_scatter"),

dataTableOutput(outputId = "countries_table")
dataTableOutput(outputId = "countries_table")
)
)
)
Expand All @@ -85,17 +86,15 @@ server <- function(input, output) {
size = input$point_size,
label = "country"))+
geom_point(alpha = input$transvalue)+
theme_minimal()+
labs(title = input$year)
theme_minimal()

ggplotly(p_scatter)
})

## create data table -------------------------------------
output$countries_table <- renderDataTable({
if(input$show_table){
datatable(countries_subset(), rownames = FALSE) ###pay attention:countries_subset()
}
if(input$show_table){countries_subset()}

})
}

Expand Down
10 changes: 4 additions & 6 deletions countries-08/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ server <- function(input, output) {

## calculate summaries per continent -----------------
countries_summary <- reactive({
countries_subset() %>% ###pay attention:countries_subset()
countries_subset() %>% ###pay attention:countries_subset() #treats as a function. return is function.
group_by(continent) %>%
summarise(gdp_median = median(gdp_per_capita, na.rm = TRUE) %>% round(2),
life_exp_median = median(life_exp, na.rm = TRUE) %>% round(2))
Expand All @@ -88,18 +88,16 @@ server <- function(input, output) {
size = input$point_size,
label = "country"))+
geom_point(alpha = input$transvalue)+
theme_minimal()+
labs(title = input$year)
theme_minimal()

ggplotly(p_scatter)
})


## create data table -------------------------------------
output$countries_table <- renderDataTable({
if(input$show_table){
datatable(countries_summary(), rownames = FALSE) ###pay attention:countries_summary()
}
if(input$show_table){countries_summary()} ###pay attention:countries_summary()

})
}

Expand Down
14 changes: 6 additions & 8 deletions countries-09/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ ui <- fluidPage(#theme = shinytheme("superhero"),
mainPanel(

## show output in multiple tabs ----------------
tabsetPanel(type = "tabs",
tabPanel(title = "Plot",
tabsetPanel(type = "tabs", #standard look
tabPanel(title = "Plot", #display title for the tab
plotlyOutput(outputId = "countries_scatter")),
tabPanel(title = "Data",
DT::dataTableOutput(outputId = "countries_table"))
dataTableOutput(outputId = "countries_table"))

)

Expand Down Expand Up @@ -107,18 +107,16 @@ server <- function(input, output) {
size = input$point_size,
label = "country"))+
geom_point(alpha = input$transvalue)+
theme_minimal()+
labs(title = input$year)
theme_minimal()

ggplotly(p_scatter)
})


## create data table -------------------------------------
output$countries_table <- renderDataTable({
if(input$show_table){
datatable(countries_summary(), rownames = FALSE) ###pay attention:countries_summary()
}
if(input$show_table){countries_summary()} ###pay attention:countries_summary()

})
}

Expand Down
49 changes: 49 additions & 0 deletions deneme3/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#

library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(

# Application title
titlePanel("Old Faithful Geyser Data"),

# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),

# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)

# Define server logic required to draw a histogram
server <- function(input, output) {

output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)

# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}

# Run the application
shinyApp(ui = ui, server = server)
Binary file modified images/subset_reactive.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 21ab2be

Please sign in to comment.