Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ugurdar authored Dec 20, 2022
0 parents commit 22666b3
Show file tree
Hide file tree
Showing 13 changed files with 1,167 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/app-1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
library(shiny)

# UI fonksiyonu
ui <- fluidPage(
textOutput("text")
)

# Server fonksiyonu
server <- function(input, output) {

output$text <- renderText({
paste("cikti-1")
})


}

# Uygulamanin calistirilmasi:
# Run App butonu bu fonksiyon varsa görünür.
shinyApp(ui = ui, server = server)
113 changes: 113 additions & 0 deletions app/app-2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
library(shiny)
# widgets'lara asagidaki linkten ulasilabilir.
# https://shiny.rstudio.com/gallery/widget-gallery.html

# Render fonksiyonu:
# Ciktinin hangi girdileri kullandigini otomatik olarak izleyen ozel bir
# reaktif baglam kurar

# R kodudunun ciktisini bir web sayfasinda goruntulemek icin HTML'e donusturur.

# UI
ui <- fluidPage(
# 1 - checkbox
# checkbox fonksiyonunda parametreler
# id, label (checkbox'da ne yazacagi), value TRUE ya da FALSE
# checkboxInput("b", label = "secenek A-1", value = FALSE),
# textOutput("text_checkb")

# # 2 - checkbox group
# checkboxlar birden fazla secenegi de barindirabilir.
# checkboxGroupInput("check_grup", label = h2("Checkbox"),
# choices = list("secenek 1" = 1, "secenek 2" = 2, "secenek 3" = "a"),
# selected = c("a")),
# textOutput("text_checkb_grup")
#
# # 3 - radiobuttons
# # Farkli secenekler icerisinden tek secenek sectirilmek istendiginde kullanilabilir
# radioButtons("radio", label = h3("Radiobuttons"),
# choices = list("Secenek 1" = 1, "Secenek 2" = 2, "Secenek 3" = 3),
# selected = 1),
# textOutput("text_radio")
#
# # 4 - numericinput
# numericInput("numeric", label = h3("Numeric girdi"), value = 5, min=3, max=7, step = 2),
# textOutput("text_numeric")
#
# # 5 - textinput
# textInput("text_girdi", label = h3("Text girdi"), value = "Text giriniz"),
# textOutput("text_girdi"),
#
# 6 - select box
# selectInput("selectbox", label = h3("Select box"),
# choices = unique(mtcars$cyl),
# selected = 1),
# textOutput('text_selectbox')
# SelectInput icerisinde birden fazla secim yapilabilir bunun
# icin multiple=TRUE olarak degistirilmelidir.
# selectInput(
# "selectbox_multi", "Select mtcars cyl", unique(mtcars$cyl),
# multiple = TRUE
# )
#
# # 7 - slider
# sliderInput("slider", label = h3("Slider"), min = 0,
# max = 100, value = 50),
# textOutput('text_slider'),
# #
# # # 8 - slider range
# sliderInput("slider_range", label = h3("Slider Range"), min = 0,
# max = 100, value = c(40, 60)),
# textOutput('text_slider_range')
#
# # 9- action button
actionButton("action", label = "Action"),
# # req(input$action) ile ciktilar kontrol edilebilir.

# 10- fluidRow fonksiyonu ile layout ayarlama.
fluidRow(
column(6,
sliderInput("slider", label = h3("Slider"), min = 0,
max = 100, value = 50, width = '70%')),
column(6,
sliderInput("slider_range", label = h3("Slider Range"), min = 0,
max = 100, value = c(40, 60)))
)
)

# Server fonksiyonu
server <- function(input, output) {
# 1 - checkbox
# output$text_checkb <- renderText({
# input$checkbox
# })
# 2 - checkbox group
output$text_checkb_grup <- renderText({
input$check_grup
})
# # 3 - radiobuttons
output$text_radio <- renderText({
input$radio
})
# # 4 - numericinput
output$text_numeric <- renderText({
input$numeric
})
# # 5 - numericinput
output$text_girdi <- renderText({
input$text_girdi
})
# # 6 - selectbox
output$text_slider <- renderText({
input$slider
})
# # 7 - slider
output$text_slider_range <- renderText({
input$slider_range
})

}

# Uygulamanin calistirilmasi
# Run App butonu bu fonksiyon varsa eklenir
shinyApp(ui = ui, server = server)
76 changes: 76 additions & 0 deletions app/app-3.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
library(shiny)
library(ggplot2)

# grafigi cizdirmek icin
freqpoly <- function(x1, x2, binwidth = 0.1, xlim = c(-3, 3)) {
df <- data.frame(
x = c(x1, x2),
g = c(rep("x1", length(x1)), rep("x2", length(x2)))
)

ggplot(df, aes(x, colour = g)) +
geom_freqpoly(binwidth = binwidth, size = 1) +
coord_cartesian(xlim = xlim)
}

# t testi sonucundan guven araliklari ve p value'yu almak icin
t_test <- function(x1, x2) {
test <- t.test(x1, x2)
sprintf(
"p value: %0.3f\n Guven araligi:[%0.2f, %0.2f]",
test$p.value, test$conf.int[1], test$conf.int[2]
)
}
# UI fonksiyonu
ui <- fluidPage(
fluidRow(
column(4,
"Distribution 1",
numericInput("n1", label = "n", value = 1000, min = 1),
numericInput("mean1", label = "mu", value = 0, step = 0.1),
numericInput("sd1", label = "sigma", value = 0.5, min = 0.1, step = 0.1)
),
column(4,
"Distribution 2",
numericInput("n2", label = "n", value = 1000, min = 1),
numericInput("mean2", label = "mu", value = 0, step = 0.1),
numericInput("sd2", label = "sigma", value = 0.5, min = 0.1, step = 0.1)
),
column(4,
"Frequency polygon",
numericInput("binwidth", label = "Bin width", value = 0.1, step = 0.1),
sliderInput("range", label = "range", value = c(-3, 3), min = -5, max = 5)
)
),
fluidRow(
column(9, plotOutput("hist")),
column(3, verbatimTextOutput("ttest"))
),
actionButton("action", label = "Cizdir")

)

# Server fonksiyonu
server <- function(input, output, session) {
output$hist <- renderPlot({
req(input$action)
x1 <- rnorm(input$n1, input$mean1, input$sd1)
x2 <- rnorm(input$n2, input$mean2, input$sd2)

freqpoly(x1, x2, binwidth = input$binwidth, xlim = input$range)
}, res = 96)
cat(1)

output$ttest <- renderText({
# req(input$action)

x1 <- rnorm(input$n1, input$mean1, input$sd1)
x2 <- rnorm(input$n2, input$mean2, input$sd2)

t_test(x1, x2)
})
}

# Uygulamanin calistirilmasi
# Run App butonu bu fonksiyon varsa eklenir
shinyApp(ui = ui, server = server)
40 changes: 40 additions & 0 deletions app/app-4.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Reaktif
# Reaktif programlamannin ana fikri, bir girdi degistiginde ilgili tum ciktilarin
# otomatik olarak guncellenmesi mantigina dayanir.
# eventReactive(),reactive(),observe(),observeEvent()

library(shiny)
library(ggplot2)
library(dplyr)

# Ornek veri seti.
dt <- data.frame(x=runif(1000), y=runif(1000))

ui <- fluidPage(
numericInput("y_ekseni", label=NULL, value=1, min=1),
actionButton("ciz","Cizdir"),

plotOutput("graph")
)

server <- function(input,output){
plot_reactive <- reactive({
plot <- ggplot(dt, aes(x,y)) +
geom_point() +
scale_y_continuous(limits = function(x){
c(min(x), input$y_ekseni)
})


return(plot)
})

output$graph <- renderPlot({
plot_reactive()
}) %>%
# Cizdir'e cizdirir. Bu eklenmez ise ilk cizdir'e basildiktan sonra
# her bir numericInput degistiginde grafik de otomatik olarak degisir.
bindEvent(input$ciz)
}

shinyApp(ui=ui, server=server)
78 changes: 78 additions & 0 deletions app/app-5.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Basit dogrusal regresyon ornegi
library(shiny)
ui <- fluidPage(
# En uste baslik yazar
titlePanel("Basit Dogrusal Regresyon Analizi"),
# Sol tarafa sidebar ekler
sidebarLayout(
# siderbarPanel ve mainPanelden olusur
# siderbarPanel ekler
sidebarPanel(
selectInput("bagimli_deg", label = h3("Bagimli degisken"),
choices =names(swiss), selected = 1),

selectInput("bagimsiz_deg", label = h3("Bagimsiz degisken"),
choices =names(swiss), selected = 1)

),
# mainPanel ekler
mainPanel(
# tabset ekler
tabsetPanel(type = "tabs",
# 1.panel scatterplot
tabPanel("Scatterplot", plotOutput("scatterplot")),
# 2.panel dagilimlar
tabPanel("Dagilimlar",
fluidRow(
column(6, plotOutput("dagilim1")),
column(6, plotOutput("dagilim2")))
),
# 3.panel model ozeti
tabPanel("Model Ozeti", verbatimTextOutput("summary")), # Regresyon ciktisi
tabPanel("Veri", DT::dataTableOutput('tbl')) # datatable olarak data ciktisi

)
)
))

# SERVER
server <- function(input, output) {

# Regressyon ciktisi
output$summary <- renderPrint({
fit <- lm(swiss[,input$bagimli_deg] ~ swiss[,input$bagimsiz_deg])
names(fit$coefficients) <- c("Intercept", input$bagimsiz_deg)
summary(fit)
})

# Datatable
output$tbl = DT::renderDataTable({
DT::datatable(swiss, options = list(lengthChange = FALSE))
})


# Scatterplot
output$scatterplot <- renderPlot({
# scatter plot cizilmesi
plot(swiss[,input$bagimsiz_deg], swiss[,input$bagimli_deg], main="Scatterplot",
xlab=input$bagimsiz_deg, ylab=input$bagimli_deg, pch=19)
# regresyon dogrusunun eklenmesi
abline(lm(swiss[,input$bagimli_deg] ~ swiss[,input$bagimsiz_deg]), col="red")
# lowess fonksiyonu snooth line grafigi cizilmesini saglar
lines(lowess(swiss[,input$bagimsiz_deg],swiss[,input$bagimli_deg]), col="blue")
}, height=400)


# Histogram-1
output$dagilim1 <- renderPlot({
hist(swiss[,input$bagimli_deg], main="", xlab=input$bagimli_deg)
}, height=300, width=300)

# Histogram-1
output$dagilim2 <- renderPlot({
hist(swiss[,input$bagimsiz_deg], main="", xlab=input$bagimsiz_deg)
}, height=300, width=300)

}

shinyApp(ui = ui, server = server)
54 changes: 54 additions & 0 deletions app/app-6.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Stock price ornegi
library(shiny)
library(dplyr)
library(quantmod)
library(highcharter)
library(DT)


ui <- fluidPage(
titlePanel("Stock Grafigi"),

sidebarLayout(
sidebarPanel(
helpText("Lutfen sembol giriniz."),
textInput("symb", "Sembol", "SPY"),

dateRangeInput("dates",
"Tarih araligi",
start = "2013-01-01",
end = as.character(Sys.Date())),
actionButton("ciz","Grafik"),
actionButton("tablo","Tablo"),
),
mainPanel(
highchartOutput("plot"),
dataTableOutput("tablo")

)
)
)

server <- function(input, output) {

dataInput <- reactive({
getSymbols(input$symb, src = "yahoo",
from = input$dates[1],
to = input$dates[2],
auto.assign = FALSE)
})

output$plot <- renderHighchart({
hchart(dataInput(), type = "ohlc") |>
hc_title(text = paste(input$symb,"-","Acilis Kapanis"))
}) %>%
bindEvent(input$ciz)

output$tablo <- renderDataTable({
datatable(dataInput())
}) %>%
bindEvent(input$tablo)

}

shinyApp(ui, server)
Loading

0 comments on commit 22666b3

Please sign in to comment.