diff --git a/shiny/hist1/server.R b/shiny/hist1/server.R new file mode 100644 index 0000000000000000000000000000000000000000..de862fc520025be724f41f6c1babe6a0e7150de1 --- /dev/null +++ b/shiny/hist1/server.R @@ -0,0 +1,21 @@ +##------------------------------------------- +## server.R + +library(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +shinyServer(function(input, output) { + output$hist.reactive <- renderPlot({ + x <- precip + hist(x, + col=paste0("#", input$html), + breaks=input$sl, + main=NULL, + ylab="Frequência absoluta", + xlab="Precipitação") + if(input$rg){ + rug(x) + } + }) +}) diff --git a/shiny/hist1/ui.R b/shiny/hist1/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..f640a20c196ceef304d61877b81feeb0e49c073f --- /dev/null +++ b/shiny/hist1/ui.R @@ -0,0 +1,30 @@ +##------------------------------------------- +## ui.R + +library(shiny) + +shinyUI(fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Histograma"), + sidebarLayout( + sidebarPanel( + sliderInput(inputId="sl", + label="Sugestão do número de classes:", + min=1, + max=20, + step=1, + value=10), + textInput(inputId="html", + label="Especifique cor em formato html:", + value="FF0000"), + checkboxInput(inputId="rg", + label="Colocar rug?", + value=FALSE) + ), + mainPanel( + plotOutput("hist.reactive") + ) + ) +)) diff --git a/shiny/hist2/server.R b/shiny/hist2/server.R new file mode 100644 index 0000000000000000000000000000000000000000..089536a4f5d96bbda160a24502b6ea20073c462d --- /dev/null +++ b/shiny/hist2/server.R @@ -0,0 +1,28 @@ +##------------------------------------------- +## server.R + +library(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +shinyServer(function(input, output) { + output$hist.reactive <- renderPlot({ + x <- precip + ## Amplitude total aumentada. + at <- extendrange(range(x), f=0.025) + ## Classes. + bks <- seq(from=at[1], to=at[2], length.out=input$cls+1) + hist(x, + col=rgb( + red=input$sr, + green=input$sg, + blue=input$sb), + breaks=bks, + main=NULL, + ylab="Frequência absoluta", + xlab="Precipitação") + if(input$rg){ + rug(x) + } + }) +}) diff --git a/shiny/hist2/ui.R b/shiny/hist2/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..507322f1ae975c6a8688dc02cd934deded754dc6 --- /dev/null +++ b/shiny/hist2/ui.R @@ -0,0 +1,30 @@ +##------------------------------------------- +## ui.R + +library(shiny) + +shinyUI(fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Histograma"), + sidebarLayout( + sidebarPanel( + sliderInput(inputId="cls", + label="Número de classes:", + min=1, max=20, step=1, value=10), + sliderInput(inputId="sr", label="R:", + min=0, max=1, step=0.05, value=0.5), + sliderInput(inputId="sg", label="G:", + min=0, max=1, step=0.05, value=0.5), + sliderInput(inputId="sb", label="B:", + min=0, max=1, step=0.05, value=0.5), + checkboxInput(inputId="rg", + label="Colocar rug?", + value=FALSE) + ), + mainPanel( + plotOutput("hist.reactive") + ) + ) +)) diff --git a/shiny/hist_button/server.R b/shiny/hist_button/server.R new file mode 100644 index 0000000000000000000000000000000000000000..1285bfd8cd3f43c678f3a03504f1c2a350ea8f0e --- /dev/null +++ b/shiny/hist_button/server.R @@ -0,0 +1,23 @@ +##------------------------------------------- +## server.R + +library(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +ht <- hist(precip) + +shinyServer( + function(input, output){ + ## Cabeçalho IGUIR2 + output$header <- renderPrint({ + template("TEMA") + }) + output$hist.reactive <- renderPlot({ + input$acao + col <- sample(colors(), size=1) + plot(ht, main=NULL, + ylab="Frequência absoluta", xlab="Precipitação", + col=col, sub=col) + }) + }) diff --git a/shiny/hist_button/ui.R b/shiny/hist_button/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..175d3f0ced5c50938fac0f773fecdaaac69dbdf5 --- /dev/null +++ b/shiny/hist_button/ui.R @@ -0,0 +1,21 @@ +##------------------------------------------- +## ui.R + +library(shiny) + +shinyUI( + fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Histograma"), + sidebarLayout( + sidebarPanel( + actionButton(inputId="acao", label="Nova cor!") + ), + mainPanel( + plotOutput("hist.reactive") + ) + ) + ) +) diff --git a/shiny/hist_checkbox/server.R b/shiny/hist_checkbox/server.R new file mode 100644 index 0000000000000000000000000000000000000000..828db384a89cfbe597d743996a1f48516210cc10 --- /dev/null +++ b/shiny/hist_checkbox/server.R @@ -0,0 +1,30 @@ +##------------------------------------------- +## server.R + +library(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +x <- precip + +ht <- hist(x) +col <- rep("#3366CC", length(ht$counts)) + +shinyServer( + function(input, output){ + ## Cabeçalho IGUIR2 + output$header <- renderPrint({ + template("TEMA") + }) + output$hist.reactive <- renderPlot({ + if(input$modal){ + col[which.max(ht$counts)] <- "#142952" + } + plot(ht, col=col, main=NULL, + ylab="Frequência absoluta", + xlab="Precipitação") + if(input$rg){ + rug(x) + } + }) + }) diff --git a/shiny/hist_checkbox/ui.R b/shiny/hist_checkbox/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..49178c84fb2227d5ab7b52e7232821379609b279 --- /dev/null +++ b/shiny/hist_checkbox/ui.R @@ -0,0 +1,26 @@ +##------------------------------------------- +## ui.R + +library(shiny) + +shinyUI( + fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Histograma"), + sidebarLayout( + sidebarPanel( + checkboxInput(inputId="rg", + label="Marcar sobre eixo com os valores?", + value=FALSE), + checkboxInput(inputId="modal", + label="Destacal a classe modal?", + value=FALSE) + ), + mainPanel( + plotOutput("hist.reactive") + ) + ) + ) +) diff --git a/shiny/hist_checkboxgroup/server.R b/shiny/hist_checkboxgroup/server.R new file mode 100644 index 0000000000000000000000000000000000000000..7b0e211b730e1c03ab19d93f5aa1ff40cf2c422c --- /dev/null +++ b/shiny/hist_checkboxgroup/server.R @@ -0,0 +1,25 @@ +##------------------------------------------- +## server.R + +library(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +x <- precip +ht <- hist(x) +nc <- length(ht$counts) + +shinyServer( + function(input, output){ + ## Cabeçalho IGUIR2 + output$header <- renderPrint({ + template("TEMA") + }) + output$hist.reactive <- renderPlot({ + seqcol <- colorRampPalette(input$colors) + plot(ht, col=seqcol(nc), + main=NULL, + ylab="Frequência absoluta", + xlab="Precipitação") + }) + }) diff --git a/shiny/hist_checkboxgroup/ui.R b/shiny/hist_checkboxgroup/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..37e5ca02e42cc6749d03ce354b83b674bad28d70 --- /dev/null +++ b/shiny/hist_checkboxgroup/ui.R @@ -0,0 +1,26 @@ +##------------------------------------------- +## ui.R + +library(shiny) + +cols <- c(Vermelho="#F81D54", Amarelo="#FF9F1E", Azul="#2791E1", Verde="#72F51D") +cols2 <- c(cols, rev(cols)) + +shinyUI( + fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Histograma"), + sidebarLayout( + sidebarPanel( + checkboxGroupInput(inputId="colors", + label="Escolha as cores para interpolar:", + choices=cols2, selected="#72F51D") + ), + mainPanel( + plotOutput("hist.reactive") + ) + ) + ) +) diff --git a/shiny/hist_numeric/server.R b/shiny/hist_numeric/server.R new file mode 100644 index 0000000000000000000000000000000000000000..9dd00a33d20bb552c523ece78c3b8c8c971a8f1f --- /dev/null +++ b/shiny/hist_numeric/server.R @@ -0,0 +1,30 @@ +##------------------------------------------- +## server.R + +library(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +x <- precip +ht <- hist(x) + +shinyServer( + function(input, output){ + ## Cabeçalho IGUIR2 + output$header <- renderPrint({ + template("TEMA") + }) + output$hist.reactive <- renderPlot({ + m <- input$mar + par(mar=c(m, m, 1, 1)) + plot(ht, col="#660066", + main=NULL, axes=FALSE, ann=FALSE, + xaxt="n", yaxt="n") + box(bty="L") + axis(side=1, cex.axis=input$cexaxis) + axis(side=2, cex.axis=input$cexaxis) + title(ylab="Frequência absoluta", + xlab="Precipitação", + line=input$line) + }) + }) diff --git a/shiny/hist_numeric/ui.R b/shiny/hist_numeric/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..6bb6316769e9aca8c185bec48b6a340c4f9b0926 --- /dev/null +++ b/shiny/hist_numeric/ui.R @@ -0,0 +1,29 @@ +##------------------------------------------- +## ui.R + +library(shiny) + +shinyUI( + fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Histograma"), + sidebarLayout( + sidebarPanel( + numericInput(inputId="cexaxis", + label="Tamanho do texto dos eixos:", + value=1, min=0.5, max=2, step=0.1), + numericInput(inputId="line", + label="Distância dos rótulos dos eixos:", + value=3, min=1, max=4, step=0.1), + numericInput(inputId="mar", + label="Tamanho do texto dos eixos:", + value=5, min=3, max=7, step=0.5) + ), + mainPanel( + plotOutput("hist.reactive") + ) + ) + ) +) diff --git a/shiny/hist_radio/server.R b/shiny/hist_radio/server.R new file mode 100644 index 0000000000000000000000000000000000000000..dc7402cfc74b4f1cc2b36f4e5e12a74e67bed5d4 --- /dev/null +++ b/shiny/hist_radio/server.R @@ -0,0 +1,24 @@ +##------------------------------------------- +## server.R + +library(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +x <- precip +ht <- hist(x) + +shinyServer( + function(input, output){ + ## Cabeçalho IGUIR2 + output$header <- renderPrint({ + template("TEMA") + }) + output$hist.reactive <- renderPlot({ + plot(ht, + col=input$col, + main=NULL, + ylab="Frequência absoluta", + xlab="Precipitação") + }) + }) diff --git a/shiny/hist_radio/ui.R b/shiny/hist_radio/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..649de6046ab725ae2ab9a868d3b1a1ce375c9119 --- /dev/null +++ b/shiny/hist_radio/ui.R @@ -0,0 +1,28 @@ +##------------------------------------------- +## ui.R + +library(shiny) + +shinyUI( + fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Histograma"), + sidebarLayout( + sidebarPanel( + radioButtons(inputId="col", + label="Escolha a cor para as barras:", + choices=c(Turquesa="#00CC99", + Azul="#0066FF", + Rosa="#FF3399", + Laranja="#FF6600", + Roxo="#660066", + "Verde limão"="#99FF33")) + ), + mainPanel( + plotOutput("hist.reactive") + ) + ) + ) +) diff --git a/shiny/hist_select/server.R b/shiny/hist_select/server.R new file mode 100644 index 0000000000000000000000000000000000000000..795cc0cb767fa351b2e5c71f04e55a97f9dc364b --- /dev/null +++ b/shiny/hist_select/server.R @@ -0,0 +1,27 @@ +##------------------------------------------- +## server.R + +library(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +shinyServer( + function(input, output){ + ## Cabeçalho IGUIR2 + output$header <- renderPrint({ + template("TEMA") + }) + output$hist.reactive <- renderPlot({ + L <- switch(input$obj, + precip=list(x=precip, xlab="Precipitação anual média (polegadas)"), + rivers=list(x=rivers, xlab="Comprimento dos rios (milhas)"), + islands=list(x=islands, xlab="Área de ilhas (1000 milhas quadradas)")) + hist(L$x, + breaks=input$nclass, + col="#8F0047", + main=NULL, + ylab="Frequência absoluta", + xlab=L$xlab) + rug(L$x) + }) + }) diff --git a/shiny/hist_select/ui.R b/shiny/hist_select/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..6bcf9dd4bcf51e58153bf68c007e2ba2e32b3ed8 --- /dev/null +++ b/shiny/hist_select/ui.R @@ -0,0 +1,29 @@ +##------------------------------------------- +## ui.R + +library(shiny) + +nclass <- c("Sturges", "Scott", "Freedman-Diaconis") +obj <- c("precip","rivers","islands") + +shinyUI( + fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Histograma"), + sidebarLayout( + sidebarPanel( + selectInput(inputId="obj", + label="Escolha o conjunto de dados:", + choices=obj), + selectInput(inputId="nclass", + label="Escolha a regra para número de classes:", + choices=nclass) + ), + mainPanel( + plotOutput("hist.reactive") + ) + ) + ) +) diff --git a/shiny/hist_select2/server.R b/shiny/hist_select2/server.R new file mode 100644 index 0000000000000000000000000000000000000000..866aa15b65cc59e0ee464762aa7c49017858848e --- /dev/null +++ b/shiny/hist_select2/server.R @@ -0,0 +1,27 @@ +##------------------------------------------- +## server.R + +library(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +x <- precip +ht <- hist(x) + +shinyServer( + function(input, output){ + ## Cabeçalho IGUIR2 + output$header <- renderPrint({ + template("TEMA") + }) + output$hist.reactive <- renderPlot({ + f <- as.integer(input$fnt) + plot(ht, + family=input$fml, + font=as.integer(input$fnt), + col="#FF9200", + main=NULL, + ylab="Frequência absoluta", + xlab="Precipitação") + }) + }) diff --git a/shiny/hist_select2/ui.R b/shiny/hist_select2/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..83275253c077556aa39295a86d3e4f628aa5c49c --- /dev/null +++ b/shiny/hist_select2/ui.R @@ -0,0 +1,29 @@ +##------------------------------------------- +## ui.R + +library(shiny) + +fml <- names(X11Fonts()) +fnt <- c("plain"=1, "bold"=2, "italic"=3, "bold-italic"=4) + +shinyUI( + fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Histograma"), + sidebarLayout( + sidebarPanel( + radioButtons(inputId="fml", + label="Escolha a fonte:", + choices=fml, selected="serif"), + radioButtons(inputId="fnt", + label="Escolha a fonte:", + choices=fnt, selected=1) + ), + mainPanel( + plotOutput("hist.reactive") + ) + ) + ) +) diff --git a/shiny/hist_slider/server.R b/shiny/hist_slider/server.R new file mode 100644 index 0000000000000000000000000000000000000000..cadfc710049c535a6c9b3f94fb311d95932fe78a --- /dev/null +++ b/shiny/hist_slider/server.R @@ -0,0 +1,28 @@ +##------------------------------------------- +## server.R + +library(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +x <- precip + +## Extremos com amplitude estendida em 5% +a <- extendrange(x, f=0.05) + +shinyServer( + function(input, output){ + ## Cabeçalho IGUIR2 + output$header <- renderPrint({ + template("TEMA") + }) + output$hist.reactive <- renderPlot({ + bks <- seq(a[1], a[2], length.out=input$nclass+1) + hist(x, + breaks=bks, + main=NULL, + col="#008A8A", + ylab="Frequência absoluta", + xlab="Precipitação") + }) + }) diff --git a/shiny/hist_slider/ui.R b/shiny/hist_slider/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..08808bc09c55c1f83d9551accb549ba657b8e9e1 --- /dev/null +++ b/shiny/hist_slider/ui.R @@ -0,0 +1,26 @@ +##------------------------------------------- +## ui.R + +library(shiny) + +shinyUI( + fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Histograma"), + sidebarLayout( + sidebarPanel( + sliderInput(inputId="nclass", + label="Número de classes:", + min=1, + max=30, + step=1, + value=10) + ), + mainPanel( + plotOutput("hist.reactive") + ) + ) + ) +) diff --git a/shiny/hist_text/server.R b/shiny/hist_text/server.R new file mode 100644 index 0000000000000000000000000000000000000000..ba15990f0132cd693019ae846187d12e59065fca --- /dev/null +++ b/shiny/hist_text/server.R @@ -0,0 +1,24 @@ +##------------------------------------------- +## server.R + +library(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +x <- precip +ht <- hist(x) + +shinyServer( + function(input, output){ + ## Cabeçalho IGUIR2 + output$header <- renderPrint({ + template("TEMA") + }) + output$hist.reactive <- renderPlot({ + plot(ht, col="#006666", + ylab="Frequência absoluta", + xlab="Precipitação", + main=input$main, + sub=input$sub) + }) + }) diff --git a/shiny/hist_text/ui.R b/shiny/hist_text/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..34cb6594822251479487c440e4b1b4fca28398ec --- /dev/null +++ b/shiny/hist_text/ui.R @@ -0,0 +1,26 @@ +##------------------------------------------- +## ui.R + +library(shiny) + +shinyUI( + fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Histograma"), + sidebarLayout( + sidebarPanel( + textInput(inputId="main", + label="Texto para o título:", + value=""), + textInput(inputId="sub", + label="Texto para o subtítulo:", + value="") + ), + mainPanel( + plotOutput("hist.reactive") + ) + ) + ) +) diff --git a/shiny/insertTemplate b/shiny/insertTemplate new file mode 100755 index 0000000000000000000000000000000000000000..6959392ca1145ac1a920b9a1e180a63694f483d8 --- /dev/null +++ b/shiny/insertTemplate @@ -0,0 +1,28 @@ +#!/bin/bash + +##====================================================================== +## Eduardo Junior +## eduardo.jr@ufpr.br +## 13-11-2015 +##====================================================================== +## Facilitando a inclusão do template em aplicacoes já elaboradas + +##------------------------------------------- +## Para os arquivos ui.R + +for file in $(find -type f -name "ui.R"); do + sed -i "1i\##-------------------------------------------\n## ui.R\n" $file + sed -i "/fluidPage(/a\ ## Cabeçalho IGUIR2\n htmlOutput(\"header\"),\n" $file +done + +##------------------------------------------- +## Para os arquivos server.R + +for file in $(find -type f -name "server.R"); do + sed -i "1i\##-------------------------------------------\n## server.R\n" $file + sed -i "/library(shiny)/a\## Carrega template das aplicações elaboradas pelo projeto iguiR2\nsource(\"../template.R\")" $file + sed -i "/require(shiny)/a\## Carrega template das aplicações elaboradas pelo projeto iguiR2\nsource(\"../template.R\")" $file + sed -i "/output){/a\ ## Cabeçalho IGUIR2\n output\$header <- renderPrint({\n template(\"TEMA\")\n })" $file + sed -i "/session){/a\ ## Cabeçalho IGUIR2\n output\$header <- renderPrint({\n template(\"TEMA\")\n })" $file +done + diff --git a/shiny/outputHTML/server.R b/shiny/outputHTML/server.R new file mode 100644 index 0000000000000000000000000000000000000000..7bab951654348380c2da4ab485e7330a97190567 --- /dev/null +++ b/shiny/outputHTML/server.R @@ -0,0 +1,20 @@ +##------------------------------------------- +## server.R + +require(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") +require(xtable) + +shinyServer( + function(input, output){ + ## Cabeçalho IGUIR2 + output$header <- renderPrint({ + template("TEMA") + }) + output$summaryAov <- renderPrint({ + m0 <- lm(Fertility~1+., + data=swiss[,c("Fertility", input$variables)]) + print(xtable(anova(m0)), type="html") + }) + }) diff --git a/shiny/outputHTML/ui.R b/shiny/outputHTML/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..e6237bf6e9653e4afc08fac48e24898bad5a7ec8 --- /dev/null +++ b/shiny/outputHTML/ui.R @@ -0,0 +1,24 @@ +##------------------------------------------- +## ui.R + +require(shiny) + +choi <- names(swiss)[-1] + +shinyUI( + fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Regressão múltipla"), + sidebarPanel( + checkboxGroupInput(inputId="variables", + label="Selecione as variáveis independentes:", + choices=choi, + selected=choi[1:2]) + ), + mainPanel( + htmlOutput("summaryAov") + ) + ) +) \ No newline at end of file diff --git a/shiny/outputTable/server.R b/shiny/outputTable/server.R new file mode 100644 index 0000000000000000000000000000000000000000..5f3e43ab7e9a26e814f9fbcdc8d62c9e619e93b7 --- /dev/null +++ b/shiny/outputTable/server.R @@ -0,0 +1,19 @@ +##------------------------------------------- +## server.R + +require(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +shinyServer( + function(input, output){ + ## Cabeçalho IGUIR2 + output$header <- renderPrint({ + template("TEMA") + }) + output$mtcarsTable <- renderDataTable({ + mtcars[,input$variables] + }, + options=list(orderClasses=TRUE)) + }) + diff --git a/shiny/outputTable/ui.R b/shiny/outputTable/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..460fd2bc3c5cf117a8e34d61ad6ae7e49f3ebf98 --- /dev/null +++ b/shiny/outputTable/ui.R @@ -0,0 +1,24 @@ +##------------------------------------------- +## ui.R + +require(shiny) + +choi <- names(mtcars) + +shinyUI( + fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Tabela de dados mtcars"), + sidebarPanel( + checkboxGroupInput(inputId="variables", + label="Selecione as variáveis:", + choices=choi, + selected=choi[1:4]) + ), + mainPanel( + dataTableOutput("mtcarsTable") + ) + ) +) \ No newline at end of file diff --git a/shiny/outputVerbatim/server.R b/shiny/outputVerbatim/server.R new file mode 100644 index 0000000000000000000000000000000000000000..cefab22f503b4e309b113310b8ef6265ccd2e589 --- /dev/null +++ b/shiny/outputVerbatim/server.R @@ -0,0 +1,19 @@ +##------------------------------------------- +## server.R + +require(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +shinyServer( + function(input, output){ + ## Cabeçalho IGUIR2 + output$header <- renderPrint({ + template("TEMA") + }) + output$summaryLm <- renderPrint({ + m0 <- lm(Fertility~1+., + data=swiss[,c("Fertility", input$variables)]) + summary(m0) + }) + }) diff --git a/shiny/outputVerbatim/ui.R b/shiny/outputVerbatim/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..09bd8d720d5d708d0b35fe4b64ca5cb006d0f027 --- /dev/null +++ b/shiny/outputVerbatim/ui.R @@ -0,0 +1,24 @@ +##------------------------------------------- +## ui.R + +require(shiny) + +choi <- names(swiss)[-1] + +shinyUI( + fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Regressão múltipla"), + sidebarPanel( + checkboxGroupInput(inputId="variables", + label="Selecione as variáveis independentes:", + choices=choi, + selected=choi[1:2]) + ), + mainPanel( + verbatimTextOutput("summaryLm") + ) + ) +) \ No newline at end of file diff --git a/shiny/transform/server.R b/shiny/transform/server.R new file mode 100644 index 0000000000000000000000000000000000000000..274f310efc5c0bb303c58df760f0572d75ceefa2 --- /dev/null +++ b/shiny/transform/server.R @@ -0,0 +1,49 @@ +##------------------------------------------- +## server.R + +##============================================================================= +## Interface para exibição do gráfico de dispersão das variáveis dist e +## speed do conjunto data(cars), aplicando transformações nas variáveis +## e ajustando uma regressão linear simples. São abordados os seguintes +## widgets: +## * Listbox +## * Checkbox +##============================================================================= + +library(shiny) +## Carrega template das aplicações elaboradas pelo projeto iguiR2 +source("../template.R") + +shinyServer(function(input, output) { + output$transformation <- renderPlot({ + ## Variáveis utilizados na aplicação + x <- cars$speed + y <- cars$dist + ## Transformando as variáveis + x <- switch(input$tx, + Identidade = x, + Quadrado = x^2, + RaizQuadrada = sqrt(x), + Log10 = log10(x) + ) + y <- switch(input$ty, + Identidade = y, + Quadrado = y^2, + RaizQuadrada = sqrt(y), + Log10 = log10(y) + ) + ## Exibindo graficamente + plot(y ~ x, pch=20, main = "Gráfico de Dispersão", + xlab = paste(input$tx, "de X", sep=" "), + ylab = paste(input$ty, "de Y", sep=" ")) + m0 <- lm(y ~ x) + r <- summary(m0)$r.squared + c <- round(cor(x, y), 3) + msg <- sprintf("R²: %0.3f \nCor: %0.3f", r, c) + if(input$reg){ + abline(coef(m0), col=4) + mtext(text = msg, side=3, cex=0.9, col=4, + adj=0.05, line=-2) + } + }) +}) diff --git a/shiny/transform/ui.R b/shiny/transform/ui.R new file mode 100644 index 0000000000000000000000000000000000000000..563c66b23938e2d7de496830d5f9b8ca9c13bd57 --- /dev/null +++ b/shiny/transform/ui.R @@ -0,0 +1,39 @@ +##------------------------------------------- +## ui.R + +##============================================================================= +## Interface para exibição do gráfico de dispersão das variáveis dist e +## speed do conjunto data(cars), aplicando transformações nas variáveis +## e ajustando uma regressão linear simples. São abordados os seguintes +## widgets: +## * Listbox +## * Checkbox +##============================================================================= + +library(shiny) + +trans <- c("Identidade", "Quadrado", "RaizQuadrada", "Log10") + +## Criando a Interface +shinyUI(fluidPage( + ## Cabeçalho IGUIR2 + htmlOutput("header"), + + titlePanel("Transformação de Variáveis"), + sidebarLayout( + sidebarPanel(width = 4, + selectInput("tx", "Transformação em X", trans, + multiple=TRUE, selectize=FALSE, + selected = "Identidade"), + selectInput("ty", "Transformação em Y", trans, + multiple=TRUE, selectize=FALSE, + selected = "Identidade"), + checkboxInput(inputId="reg", + label="Ajuste de Regressão Linear", + value=FALSE) + ), + mainPanel(width = 8, + plotOutput("transformation") + ) + ) +))