diff --git a/inst/ShinyApps/labestDataView/server.R b/inst/ShinyApps/labestDataView/server.R index 04b44e16bc065d8c9d5995cdef5e916609bcecd8..d1db4c74411992c3d4a5a4f70025e0dc6798c52d 100644 --- a/inst/ShinyApps/labestDataView/server.R +++ b/inst/ShinyApps/labestDataView/server.R @@ -1,3 +1,6 @@ +##------------------------------------------- +## server.R + library(shiny) library(xtable) @@ -12,40 +15,52 @@ howmanydigits <- function(x) { } } -shinyServer(function(input, output) { - 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) +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$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$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$LINK <- renderUI({ - HTML(sprintf(paste0('<center><a href="http://127.0.0.1:%d', - '/library/labestData/html/%s.html" target="_blank">', - 'Documentação</a></center>'), - input$PORTA, - input$DATASET)) - }) -}) + } +) diff --git a/inst/ShinyApps/labestDataView/ui.R b/inst/ShinyApps/labestDataView/ui.R index 08d2cc47ab13820e7797100b72a3286232e65be5..9942660c7f05ee14698bd671b09efa351de9869f 100644 --- a/inst/ShinyApps/labestDataView/ui.R +++ b/inst/ShinyApps/labestDataView/ui.R @@ -1,6 +1,8 @@ +##------------------------------------------- +## ui.R + library(shiny) -library(xtable) -library(labestData, lib.loc = "/home/walmes/R/") +library(labestData, lib.loc = installed.packages()["labestData", 2]) L <- ls("package:labestData") i <- sapply(L, @@ -16,23 +18,28 @@ shinyUI(fluidPage( 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(), - numericInput(inputId ="PORTA", - label = "Porta:", - value = options()$html.port), - uiOutput("LINK"), - hr(), - downloadButton(outputId = "DOWNLOADDATA", - label = "Download tsv") - ), - mainPanel( - htmlOutput("TABLE") - ) # mainPanel - ) # sidebarLayout -)) # fluidPage shinyUI + + sidebarLayout( + sidebarPanel( + selectInput(inputId = "DATASET", + label = "Escolha o dataset:", + choices = L, + selected = sample(1:length(L))), + hr(), + downloadButton(outputId = "DOWNLOADDATA", + label = "Download tsv") + ), + mainPanel( + tabsetPanel( + tabPanel( + title = "Tabela de dados", + htmlOutput("TABLE")), + tabPanel( + title = "Documentação", + htmlOutput("DOC") + ) + ) + ) + ) + ) +)