Skip to content
Snippets Groups Projects
Select Git revision
  • f1f8ff04e450909cd3b8ce0174e8779c405bc052
  • devel default protected
  • eduardo217
  • jhenifer207
  • jhenifer128
  • jhenifer126
  • jhenifer125
  • guilherme190
  • lineu180
  • lineu181
  • bruna141
  • bruna216
  • altamiro187
  • maria134
  • maria133
  • maria132
  • vinicius177
  • vinicius176
  • vinicius173
  • vinicius210
  • ludmila155
21 results

server.R

Blame
  • Eduardo Junior's avatar
    Eduardo E. R. Junior authored
    - 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
    f1f8ff04
    History
    server.R 2.51 KiB
    ##-------------------------------------------
    ## 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$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),
                            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")
            })
    
            output$DOWNLOADDATA <- downloadHandler(
                filename = function() {
                    sprintf("%s.txt", input$DATASET)
                },
                content = function(file) {
                    write.table(eval(parse(text = input$DATASET)),
                                file = file,
                                sep = "\t",
                                row.names = FALSE,
                                quote = FALSE)
                })
    
            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"))
                }
            })
        }
    )