From f1f8ff04e450909cd3b8ce0174e8779c405bc052 Mon Sep 17 00:00:00 2001
From: Eduardo Junior <edujrrib@gmail.com>
Date: Fri, 18 Mar 2016 21:59:14 -0300
Subject: [PATCH] =?UTF-8?q?Altera=20layout=20da=20aplica=C3=A7=C3=A3o?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- Deixa layout no formato longo
- Cria widgets de seleção para exibição (tabela ou documentação)
- Deixa a exibição dos widgets condicional a primeira opção
  selecionada
---
 inst/ShinyApps/labestDataView/server.R | 31 ++++++++++---
 inst/ShinyApps/labestDataView/ui.R     | 63 +++++++++++++++-----------
 2 files changed, 62 insertions(+), 32 deletions(-)

diff --git a/inst/ShinyApps/labestDataView/server.R b/inst/ShinyApps/labestDataView/server.R
index d1db4c74..3267e980 100644
--- a/inst/ShinyApps/labestDataView/server.R
+++ b/inst/ShinyApps/labestDataView/server.R
@@ -3,6 +3,7 @@
 
 library(shiny)
 library(xtable)
+library(labestData, lib.loc = "/usr/lib/R/site-library")
 
 howmanydigits <- function(x) {
     x <- na.omit(x)
@@ -27,6 +28,18 @@ static_help <- function(pkg, topic, out,
 
 shinyServer(
     function(input, output, session) {
+        output$test <- renderPrint({
+            input$VIEW
+        })
+
+        output$DOC <- renderPrint({
+            tmp <- tempfile()
+            static_help("labestData", input$DATASET, tmp)
+            out <- readLines(tmp)
+            headfoot <- grep("body", out)
+            cat(out[(headfoot[1] + 1):(headfoot[2] - 2)], sep = "\n")
+        })
+
         output$TABLE <- renderPrint({
             da <- eval(parse(text = input$DATASET))
             a <- switch(class(da),
@@ -44,6 +57,7 @@ shinyServer(
             dig <- sapply(a, howmanydigits)
             print(xtable(a, digits = c(0, dig)), type = "html")
         })
+
         output$DOWNLOADDATA <- downloadHandler(
             filename = function() {
                 sprintf("%s.txt", input$DATASET)
@@ -55,12 +69,17 @@ shinyServer(
                             row.names = FALSE,
                             quote = FALSE)
             })
-        output$DOC <- renderPrint({
-            tmp <- tempfile()
-            static_help("labestData", input$DATASET, tmp)
-            out <- readLines(tmp)
-            headfoot <- grep("body", out)
-            cat(out[(headfoot[1] + 1):(headfoot[2] - 2)], sep = "\n")
+
+        output$TABLE_DOC <- renderUI({
+            if(input$VIEW == "about") {
+                return(HTML("<b>README</b>"))
+            }
+            if(input$VIEW == "table") {
+                return(tableOutput("TABLE"))
+            }
+            if(input$VIEW == "doc") {
+                return(uiOutput("DOC"))
+            }
         })
     }
 )
diff --git a/inst/ShinyApps/labestDataView/ui.R b/inst/ShinyApps/labestDataView/ui.R
index 084cb962..3170d6f1 100644
--- a/inst/ShinyApps/labestDataView/ui.R
+++ b/inst/ShinyApps/labestDataView/ui.R
@@ -2,6 +2,7 @@
 ## ui.R
 
 library(shiny)
+library(labestData, lib.loc = "/usr/lib/R/site-library")
 
 L <- ls("package:labestData")
 i <- sapply(L,
@@ -10,35 +11,45 @@ i <- sapply(L,
             })
 L <- L[i %in% c("data.frame", "numeric", "integer")]
 
-shinyUI(fluidPage(
-    includeCSS("palatino.css"),
-    # titlePanel("labestData"),
-    h1("labestData"),
-    h3("Conjuntos de Dados para Ensino de Estatística"),
-    tags$em("pet.estatistica.ufpr@gmail.com"),
-    hr(),
-
-        sidebarLayout(
-            sidebarPanel(
-                selectInput(inputId = "DATASET",
-                            label = "Escolha o dataset:",
-                            choices = L,
-                            selected = sample(1:length(L))),
-                hr(),
-                downloadButton(outputId = "DOWNLOADDATA",
-                               label = "Download tsv")
+shinyUI(
+    fluidPage(
+        includeCSS("palatino.css"),
+        title = "labestData",
+        fluidRow(
+            column(
+                width = 4,
+                selectInput(inputId = "VIEW",
+                            label = "Exibir:",
+                            choices = c(
+                                "Sobre o projeto" = "about",
+                                "Tabela de dados" = "table",
+                                "Documentação" = "doc")
+                            )
             ),
-            mainPanel(
-                tabsetPanel(
-                    tabPanel(
-                        title = "Tabela de dados",
-                        htmlOutput("TABLE")),
-                    tabPanel(
-                        title = "Documentação",
-                        htmlOutput("DOC")
-                    )
+
+            conditionalPanel(
+                "input.VIEW != 'about'",
+                column(
+                    width = 4,
+                    selectInput(inputId = "DATASET",
+                                label = "Escolha o dataset:",
+                                choices = L,
+                                selected = sample(1:length(L)))
+                ),
+                column(
+                    width = 4,
+                    HTML('<label class="control-label">Baixe os dados:</label><br>'),
+                    downloadButton(outputId = "DOWNLOADDATA",
+                                   label = "Download tsv")
                 )
             )
+        ),
+
+        fluidRow(
+            uiOutput("TABLE_DOC"),
+            style = "overflow-y:scroll; max-height: 600px"
         )
     )
 )
+
+
-- 
GitLab