From 35d42a078520cb6cb2ad56cbf9b06ed2e59e3809 Mon Sep 17 00:00:00 2001 From: Eduardo Junior <edujrrib@gmail.com> Date: Sat, 19 Mar 2016 17:44:28 -0300 Subject: [PATCH] Modifica funcionamento e layout do labestDataView app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Funções e objetos não reativos foram removidos de ui.R e server.R - Adiciona cabeçalho simples - Condiciona a aplicação somente a seleção do dataset. Quando não selecionado exibe as informações sobre o projeto. --- inst/ShinyApps/labestDataView/server.R | 98 +++++++++++--------------- inst/ShinyApps/labestDataView/ui.R | 50 ++++--------- 2 files changed, 57 insertions(+), 91 deletions(-) diff --git a/inst/ShinyApps/labestDataView/server.R b/inst/ShinyApps/labestDataView/server.R index 3267e980..dd8a6c97 100644 --- a/inst/ShinyApps/labestDataView/server.R +++ b/inst/ShinyApps/labestDataView/server.R @@ -1,61 +1,49 @@ ##------------------------------------------- ## server.R -library(shiny) -library(xtable) -library(labestData, lib.loc = "/usr/lib/R/site-library") - -howmanydigits <- function(x) { - x <- na.omit(x) - if (is.numeric(x) && all(x%%1 == 0)) { - 0 - } else if (is.numeric(x)) { - 1 + floor(log10(1/min(diff(sort(unique(x)))))) - } else { - 0 - } -} - -static_help <- function(pkg, topic, out, - links = tools::findHTMLlinks()) { - pkgRdDB = tools:::fetchRdDB(file.path( - find.package(pkg), 'help', pkg)) - force(links) - tools::Rd2HTML(pkgRdDB[[topic]], out, package = pkg, - Links = links, no_links = is.null(links)) -} - - shinyServer( function(input, output, session) { - output$test <- renderPrint({ - input$VIEW + + output$HEADER <- renderPrint({ + vers <- as.character(packageVersion("labestData")) + tagList( + h1(paste("labestData: Conjuntos de dados para", + "Ensino de Estatística"), class = "title"), + h2(paste("PET-Estatística UFPR - Versão", vers), + class = "title"), + hr() + ) }) 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") + if (input$DATASET != "") { + 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") + } else return("Processando") }) output$TABLE <- renderPrint({ - da <- eval(parse(text = input$DATASET)) - a <- switch(class(da), - data.frame = da, - numeric = { - da <- data.frame(da) - names(da) <- input$DATASET - da - }, - integer = { - da <- data.frame(da) - names(da) <- input$DATASET - da - }) - dig <- sapply(a, howmanydigits) - print(xtable(a, digits = c(0, dig)), type = "html") + if (input$DATASET != "") { + da <- eval(parse(text = input$DATASET)) + a <- switch(class(da), + data.frame = da, + numeric = { + da <- data.frame(da) + names(da) <- input$DATASET + da + }, + integer = { + da <- data.frame(da) + names(da) <- input$DATASET + da + }) + dig <- sapply(a, howmanydigits) + print(xtable(a, digits = c(0, dig)), type = "html") + } else return("Processando") }) output$DOWNLOADDATA <- downloadHandler( @@ -71,14 +59,14 @@ shinyServer( }) 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")) + if(input$DATASET == "") { + return(includeMarkdown("ABOUT.md")) + } else { + tabsetPanel( + tabPanel("Documentação", uiOutput("DOC")), + tabPanel("Tabela de dados", + tableOutput("TABLE")) + ) } }) } diff --git a/inst/ShinyApps/labestDataView/ui.R b/inst/ShinyApps/labestDataView/ui.R index 3170d6f1..eb3d3d58 100644 --- a/inst/ShinyApps/labestDataView/ui.R +++ b/inst/ShinyApps/labestDataView/ui.R @@ -1,55 +1,33 @@ ##------------------------------------------- ## ui.R -library(shiny) -library(labestData, lib.loc = "/usr/lib/R/site-library") - -L <- ls("package:labestData") -i <- sapply(L, - function(x) { - class(eval(parse(text = x))) - }) -L <- L[i %in% c("data.frame", "numeric", "integer")] - shinyUI( fluidPage( includeCSS("palatino.css"), title = "labestData", + htmlOutput("HEADER"), + fluidRow( column( - width = 4, - selectInput(inputId = "VIEW", - label = "Exibir:", - choices = c( - "Sobre o projeto" = "about", - "Tabela de dados" = "table", - "Documentação" = "doc") - ) + width = 4, offset = 2, + selectInput(inputId = "DATASET", + label = "Dados disponíveis", + choices = c("Escolha um dataset" = "", L)) ), - - 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") - ) + column( + width = 4, + HTML(paste('<label class="control-label">Baixe ', + 'os dados:</label><br>', sep = "")), + downloadButton(outputId = "DOWNLOADDATA", + label = "Download tsv") ) ), fluidRow( - uiOutput("TABLE_DOC"), - style = "overflow-y:scroll; max-height: 600px" + uiOutput("TABLE_DOC") ) ) ) + -- GitLab