2
|
library(shiny)
shinyUI(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),
actionLink("link","Zadajte link: "),
actionButton("button","Potvrd"),
checkboxGroupInput("checkbox", "Výber možnosti",
choices = c("ano", "nie", "mozno"), selected = "ano"),
checkboxInput("checkbox1", "Zaškrtni možnosť"),
dateInput("datum","Zadajte datum", value = Sys.Date(), format = "dd.mm.yyyy",
min = Sys.Date() - 5, max = Sys.Date()+ 5, language = "sk", startview = "year",
weekstart = 3),
dateRangeInput("datum2", "Zadajte rozsah",
start = Sys.Date() - 6, end = Sys.Date() + 4 ,min = NULL, max = NULL,
format = "yyyy-mm-dd", startview = "month", weekstart = 0,
language = "en", separator = "do"),
fileInput("subor", "Nahrajte súbor", multiple = TRUE,
accept = NULL),
numericInput("cislo", "Zadajte číslo", value = 18, min = 1, max = 25,
step = 3),
passwordInput("heslo","Zadajte heslo", value = "qwertz"),
radioButtons("radio","Vyberte jednú z možností", choices = c(1,2,5),
selected = 5),
selectInput("select", "Vyberte možnosť", choices = c("včera","dnes","zajtra"),
selected = "zajtra", multiple = TRUE, selectize = TRUE, width = "400px"),
# submitButton("GO"),
wellPanel(
textInput("text","Zadajte vstup", value = "a"),
actionButton("goButton", "Spusť")
),
conditionalPanel(condition = "input.cislo == 18",
selectInput("select2", "Výber", choices = c("rok", "mesiac", "den"),
selected = "mesiac"))
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot"),
verbatimTextOutput("distPrint"),
tableOutput("distTable"),
dataTableOutput("distDataTable"),
textOutput("distText"),
textOutput("Text"),
textOutput("Text2"),
textOutput("Text3")
title: "Moja prezentácia„
output: beamer_presentation
---
## Slajd s odrážkami
- Názov 1
- Názov 2
- Názov 3
## Slajd s R kódom a výstupom
```{r}
summary(cars)
```
## Slajd s grafom
Linky
– Priamo uvedieme linku ... odkaz
– alebo s vl. textom ... [moj text]( odkaz
• Obrázky
![moj text]( odkaz
![moj text](figures/img.png)
• Blok „citácie“
> Toto je citácia v bloku
• Horizontálna čiara
********
• Tabuľky
Názov 1 | Názov 2 | Názov 3
------- | ------- | -------
Hodnota 1.1 | Hodnota 1.2 | Hodnota 1.3
Hodnota 2.1 | Hodnota 2.2 | Hodnota 2.3
• Inline rovnice (Latex)
$A = \pi*r^{2}$
|
|
|
3
|
SERVER
library(shiny)
shinyServer(function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
state.x77 <- faithful[, 2]
numeric <- seq(min(state.x77), max(state.x77), length.out = input$numeric + 1)
# draw the histogram with the specified number of bins
hist(state.x77, input$select, breaks = input$numeric, col = input$radio)
})
})
|
|
|
9
|
|
3. 09.12.2015, 18:17
SERVER
library(shiny)
shinyServer(function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
state.x77 <- faithful[, 2]
numeric <- seq(min(state.x77), max(state.x77), length.out = input$numeric + 1)
# draw the histogram with the specified number of bins
hist(state.x77, input$select, breaks = input$numeric, col = input$radio)
})
})
▲
10.12.2015, 13:35
|
# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# odkaz
#
library(shiny)
shinyServer(function(input, output) {
x <- reactive({as.numeric(input$text)+100})
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')
})
output$distPrint <- renderPrint({
print(input$text)
})
output$distTable <- renderTable({
head(iris)
})
output$distDataTable <- renderDataTable({
head(mtcars)
})
output$distText <- renderText({
paste("Zadali ste rozsah dátumu ", input$datum2[1], " do ", input$datum2[2])
})
output$Text <- renderText({
x()
})
output$Text2 <- renderText({
x() + as.numeric(input$cislo)
})
output$Text3 <- renderText({
input$goButton
isolate(paste("Zadali ste čísla ", input$text, " a" ,input$cislo))
})
})
|
|
|
4
|
eval ... TRUE/FALSE – vypíše/nevypíše „výpočet“ (def. TRUE)
– echo ... TRUE/FALSE – vypíše/nevypíše „zdroják“ (def. TRUE)
|
|
|
5
|
##sustava linearnych rovnic
priklad 1
6x1+3x2-2x3=2
x1-3x2+3x2=5
2x1+x2+x3
A=matrix(nrow=3, ncol =3, data=c(6,1,2,3,-3,1,-2,2,1))
b=c(2,5,9)
solve(A,b)
priklad2
A2=matrix(nrow=4, ncol=4, data=c(4,3,2,5,-3,-2,-1,-3,2,1,0,1,-1,-3,5,-8))
b2=c(8,7,6,1)
solve(A2,b2)
##Riesenie nelinearnny rovnic
curve(2*cos(x), 0,10) #0,10 je interval
curve(log(x), add=TRUE, col="blue")
f=function(x) 2*cos(x)- log(x)
uniroot(f,lower=0,upper=2,tol=1e-9) #ffunkcia,lower–ľavá hodnota,upper– pravá hodnota intervalu, tol
curve(2*sin(x),-5,10)
curve(2*x, add=TRUE, col="red")
#linearna regresia:
x=c(3,8,9,13,3,6,11,21,1,16)
y=c(30,57,64,72,36,43,59,90,20,83)
mydata=data.frame(x.y)
model = glm(y ~ x, data=mydata)
#viacnasobna regresia:
year <- rep(2008:2010, each = 4)
quarter <- rep(1:4, 3)
cpi <- c(162.2, 164.6, 166.5, 166, 166.2, 167,
168.6, 169.5, 171, 172.1, 173.3, 174)
plot(cpi, xaxt = "n", ylab = "CPI", xlab = "")
axis(1, labels = paste(year, quarter, sep = "Q"), at = 1:12, las = 3)
##axis vykresli popis x-osi, kde 'las=3' zabezpeci vertikalny text
#interpolizacia kriviek Príklad: dáta – sin(x) + odchýlky
set.seed()
n<-500
dat<=data.frame(
x:1:n,
y = sin(seq(0, 5*pi, length.out = n)) + rnorm(n=n,mean= 0, sd=0.5)
)
#kody pre interpolizaciu kriviek
approxData <- data.frame( with(dat, approx(x, y, method = "linear") ),
metoda = "approx“ )
splineData <- data.frame( with(dat, spline(x, y) ), metoda = "spline
default")
splineData2 <- data.frame( with(dat, spline(x, y, xout = seq(1, n, by = 10),
method = "fmm") ), metoda = "spline krok 10")
smoothData <- data.frame( x = 1:n, y = as.vector(smooth(dat$y)),
metoda = "smooth")
loessData <- data.frame( x = 1:n, y = predict(loess(y~x, dat, span = 0.1)),
metoda = "loess span 0.1")
##linearne programovaniePriklad
Máme problém definovaný nasledovne:
KF : max(143x + 60y)
120x + 210y <= 15000
110x + 30y <= 4000
x + y <= 75
x >= 0
y >= 0
> install.packages("lpSolveAPI“)
> library(lpSolveAPI)
#Reprezentacia problemu lpSolveAPI
> lpmodel <- make.lp(0, 2) # prazdny LP solver s 2
premennymi
> lp.control(lpmodel, sense="max") # maximalizacia
> set.objfn(lpmodel, c(143, 60)) # definicia KF (v
anglictine casto objective function)
> add.constraint(lpmodel, c(120, 210), "<=", 15000)
> add.constraint(lpmodel, c(110, 30), "<=", 4000)
> add.constraint(lpmodel, c(1, 1), "<=", 75)
>lp model
#linearne programovanie
#Riešenie – použitie solve funkcie
solve(lpmodel)
get.objective(lpmodel) ## dosiahnuta hodnota KF
get.variables(lpmodel) ##hodnoty premennych pre opptimum
##celociselne programovanie
##priklad
#Príklad – priradzovací problém (assignment)
– Matica nákladov priradenia i-tého objektu do j-tého miesta – COST
matica – známa
– Cieľ: rozhodnúť o matici priradení X, kde bude 1 tam kde platí že i-tý
objekt ide do j-tého miesta, inak 0 ak i-tý objekt do j-tého miesta
nedávame => to všetko za predpokladu minimálnych nákladov
– Použijeme lpSolve balík (má priamo ľahko aplikovateľnú lp.assign
funkciu pre tento problém)
> library(lpSolve)
> assign.costs <- matrix (c(7, 7, 3, 2, 2, 7, 7, 2, 1, 9, 8, 2, 7, 2, 8, 10), 4, 4)
> lp.assign (assign.costs)
> lp.assign (assign.costs)$solution
##Optimalizacia v R
library(TSP)
# vytvorenie dát – náhodných „miest“, mená priradené z letters konštanty
df <- data.frame(x = runif(20), y = runif(20), row.names = LETTERS[1:20])
# vytvorenie Euklidovskeho TSP
etsp <- ETSP(df)
# výpis detailov – počet miest, názvy miest
n_of_cities(etsp) # vypíše [1] 20
labels(etsp) # vypíše názvy [1] "A" "B" "C" ....
# nájdenie riešenia a jeho vykreslenie
tour <- solve_TSP(etsp)
tour
plot(etsp, tour, tour_col = "red")
|
|
|
6
|
|
5. 09.12.2015, 18:19
##sustava linearnych rovnic
priklad 1
6x1+3x2-2x3=2
x1-3x2+3x2=5
2x1+x2+x3
A=matrix(nrow=3, ncol =3, data=c(6,1,2,3,-3,1,-2,2,1))
b=c(2,5,9)
solve(A,b)
priklad2
A2=matrix(nrow=4, ncol=4, data=c(4,3,2,5,-3,-2,-1,-3,2,1,0,1,-1,-3,5,-8))
b2=c(8,7,6,1)
solve(A2,b2)
##Riesenie nelinearnny rovnic
curve(2*cos(x), 0,10) #0,10 je interval
curve(log(x), add=TRUE, col="blue")
f=function(x) 2*cos(x)- log(x)
uniroot(f,lower=0...
▲
09.12.2015, 18:20
|
zasmradiť hlavnú plochu z debilitami!!!
|
|
|
7
|
Nevies si predstavit ako to yasmradi hlavu tolko prikazov :D
|
|
|
8
|
Skoda ze sa v tom R nedaju robit nejake animacie 🙂
|
|
|
10
|
selectInput("select", "Vyberte atribut", choices = colnames(state.x77)),
|
|
|
11
|
sidebarLayout(
sidebarPanel(
selectInput("select", "Vyberte atribut", choices = colnames(state.x77)),
radioButtons("radio", "Vyberte farbu grafu", choices = c("blue", "red")),
numericInput("numeric", "Zadanie rozdelnie histpgramu", value = 12, min = 2, max = 20),
numericInput("numeric1", "Pocet riadkov", value=12, min=1, max=50)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot"),
tableOutput("distTable")
)
)
))
|
|
|
12
|
state.x77 <- faithful[, 2]
numeric <- seq(min(state.x77), max(state.x77), length.out = input$numeric + 1)
# draw the histogram with the specified number of bins
hist(state.x77, input$select, breaks = input$numeric1, col = input$radio)
})
|
|
|
13
|
server
# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# odkaz
#
library(shiny)
shinyServer(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')
})
})
ui ui ui ui ui ui ui ui
# This is the user-interface definition of a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# odkaz
#
library(shiny)
shinyUI(fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
flowLayout(
actionLink("link","Zadajte link: "),
actionButton("button","Potvrd"),
checkboxGroupInput("checkbox", "Výber možnosti",
choices = c("ano", "nie", "mozno"), selected = "ano")
),
splitLayout(
actionLink("link","Zadajte link: "),
radioButtons("radio","Vyberte jednú z možností", choices = c(1,2,5),
selected = 5)
# checkboxGroupInput("checkbox", "Výber možnosti",
# choices = c("ano", "nie", "mozno"), selected = "ano")
),
verticalLayout(
actionLink("link","Zadajte link: "),
actionButton("button","Potvrd"),
checkboxGroupInput("checkbox", "Výber možnosti",
choices = c("ano", "nie", "mozno"), selected = "ano")
),
# 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")
)
)
))
|
|
|
14
|
UIuiUIui UI ui ui - tab panel
# This is the user-interface definition of a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# odkaz
#
library(shiny)
shinyUI(fluidPage(
tabsetPanel(
tabPanel(
title = "Page"
),
tabPanel("tab2",
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
tabPanel("tab3",
plotOutput("distPlot"))
)
)
)
--------------------------------server
# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# odkaz
#
library(shiny)
shinyServer(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')
})
})
|
|
|
15
|
Dynamically generated user interface components
UI
# This is the user-interface definition of a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# odkaz
#
library(shiny)
shinyUI(fluidPage(
titlePanel("Dynamically generated user interface components"),
fluidRow(
column(3, wellPanel(
selectInput("input_type", "Input type",
c("slider", "text", "numeric", "checkbox",
"checkboxGroup", "radioButtons", "selectInput",
"selectInput (multi)", "date", "daterange"
)
)
)),
column(3, wellPanel(
# This outputs the dynamic UI component
uiOutput("ui")
)),
column(3,
tags$p("Input type:"),
verbatimTextOutput("input_type_text"),
tags$p("Dynamic input value:"),
verbatimTextOutput("dynamic_value")
)
)
))
SEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEERVER
# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# odkaz
#
library(shiny)
shinyServer(function(input, output) {
output$ui <- renderUI({
if (is.null(input$input_type))
return()
# Depending on input$input_type, we'll generate a different
# UI component and send it to the client.
switch(input$input_type,
"slider" = sliderInput("dynamic", "Dynamic",
min = 1, max = 20, value = 10),
"text" = textInput("dynamic", "Dynamic",
value = "starting value"),
"numeric" = numericInput("dynamic", "Dynamic",
value = 12),
"checkbox" = checkboxInput("dynamic", "Dynamic",
value = TRUE),
"checkboxGroup" = checkboxGroupInput("dynamic", "Dynamic",
choices = c("Option 1" = "option1",
"Option 2" = "option2"),
selected = "option2"
),
"radioButtons" = radioButtons("dynamic", "Dynamic",
choices = c("Option 1" = "option1",
"Option 2" = "option2"),
selected = "option2"
),
"selectInput" = selectInput("dynamic", "Dynamic",
choices = c("Option 1" = "option1",
"Option 2" = "option2"),
selected = "option2"
),
"selectInput (multi)" = selectInput("dynamic", "Dynamic",
choices = c("Option 1" = "option1",
"Option 2" = "option2"),
selected = c("option1", "option2"),
multiple = TRUE
),
"date" = dateInput("dynamic", "Dynamic"),
"daterange" = dateRangeInput("dynamic", "Dynamic")
)
})
output$input_type_text <- renderText({
input$input_type
})
output$dynamic_value <- renderPrint({
str(input$dynamic)
})
})
|
|
|
|