Skip to content
Snippets Groups Projects
Commit 15789143 authored by Walmes Marques Zeviani's avatar Walmes Marques Zeviani
Browse files

Adiciona arquivos para aplicação shiny em inst/.

parent e420f0f6
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,7 @@ Suggests:
ggplot2,
car,
knitr,
rmarkdown
rmarkdown,
shiny
VignetteBuilder: knitr
RoxygenNote: 5.0.1
# Generated by roxygen2: do not edit by hand
# Generated by roxygen2 (4.1.1): do not edit by hand
export(labestDataView)
#' @name labestDataView
#' @title Shiny App para Visualização e Download dos Datasets
#' @author Walmes Zeviani e Eduardo Ribeiro Jr.
#' @description Essa função abre uma interface \pkg{shiny} para
#' visualizar as tabelas de dados e consultar a documentação. Além
#' disso, tem um botão para salvar o dado em txt.
#' @section Warning: Para funcionar, é necessário ter o pacote shiny
#' instalado. Para abrir a documentação dos datasets é necessário
#' informar o número da porta que o navegador usa
#' (\code{http://127.0.0.1:XXXXX}) para exibir a documentação em
#' html. Para ter esse número, peça a documentação de alguma
#' função antes de chamar a aplicação. Veja na seção exemplos como
#' fazer.
#' @return Abre uma aplicação web com shiny.
#' @usage labestDataView()
#' @export
#' @examples
#' \dontrun{
#'
#' options(help.ports = 1111)
#' help(BanzattoQd1.2.3, help_type = "html")
#' help(package = "labestData", help_type = "html")
#'
#' labestDataView()
#'
#' }
labestDataView <- function() {
if (!requireNamespace(package = "shiny", quietly = TRUE)) {
stop("Pacote `shiny` não encontrado. Instale-o, por favor.",
call. = FALSE)
}
appDir <- system.file("ShinyApps",
"labestDataView",
package = "labestData")
if (appDir == "") {
stop(paste(
"Não foi possível encontrar diretório",
"com a aplicação Shiny.",
"Tente reinstalar o `labestData`."),
call. = FALSE)
}
shiny::runApp(appDir, display.mode = "normal")
}
/*
=============================================================================
Arquivo de definições CSS para usar em arquivos R Markdown
Walmes Zeviani
--------------------------------------------
O padrão do markdown fica em:
/usr/lib/R/site-library/markdown/resources/markdown.css
=============================================================================
Esse estilo usa fonte serif (Palatino) e palheta de cores para o
código R inspirados no tema default do Emacs.
*/
/*
-----------------------------------------------------------------------------
Fonte, paragráfo, cores, margens, legendas
-----------------------------------------------------------------------------
*/
body, td, caption {
font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
background-color: white;
font-size: 14px;
}
body {
max-width: 800px;
margin: auto;
/* padding: 5em; */
line-height: 22px;
}
tt, code, pre {
/* font-family: "Lucida Console", Monaco, monospace; */
/* font-family: Consolas, "Courier New", Courier, monospace; */
font-family: "Andale Mono", monospace;
}
code, pre {
font-size: 13px;
}
p {
margin-top: 1em;
margin-bottom: 1em;
}
/* Será usando para tabelas. */
figcaption {
width: 95%;
margin-left: 2.5%;
margin-top: 0.5em;
margin-bottom: 0.5em;
font-size: 14px;
}
figcaption.tab {
width: 95%;
margin-left: 2.5%;
margin-top: 0.25em;
margin-bottom: -0.5em;
font-size: 14px;
}
/*
-----------------------------------------------------------------------------
Estilo de código de acordo com edit-emacs.css ou o mais próximo do
emacs possível.
-----------------------------------------------------------------------------
*/
/* Parênteses, colchetes, chaves, pontuação, !, <-, ... */
pre .paren {
color: rgb(104, 118, 135)
}
/* Palavras reservadas: NULL, NA, Inf, NaN, TRUE, FALSE, T, F */
pre .literal {
/* color: #990073 */
color: #00CC00
}
/* Números. */
pre .number {
/* color: #099; */
color: #006332;
}
/* Comentários. */
pre .comment {
/* color: #ac2020; */
color: #998;
font-style: italic
}
/* Funções especiais: function, require, if, else, stop, for, return,
while, break, ... */
pre .keyword {
/* color: #900; */
color: #0000FF;
font-weight: bold
}
/* Texto para nome de objetos (preto). */
pre .identifier {
color: rgb(0, 0, 0);
}
/* Strings. */
pre .string {
/* color: #bd8d8b; */
color: #d14;
}
/*
-----------------------------------------------------------------------------
Tabelas
-----------------------------------------------------------------------------
*/
/* Center the table and add top/bottom margins */
table {
/* page-break-before: always; */
/* display: table; */
/* float: left; */
/* margin: auto; */
margin-left: auto;
margin-right: auto;
margin-top: 1em;
margin-bottom: 1em;
border: none;
border-top: 2px solid #000000;
border-bottom: 2px solid #000000;
border-left: 0px;
border-right: 0px;
/* border-collapse: separate; */
border-collapse: collapse;
}
table.none {
border-top: 0px solid #000000;
border-bottom: 0px solid #000000;
}
table.wide {
width: 95%;
}
th, td, tr {
color: #000000;
border-bottom: 0px;
border-top: 0px;
border-left: 0px;
border-right: 0px;
padding-left: 15px;
padding-right: 15px;
padding-top: 1px;
padding-bottom: 0px;
}
th {
border-bottom: 1px solid #000000;
}
th.none {
border-bottom: 0px solid #000000;
}
/*
-----------------------------------------------------------------------------
Padrões para fazer destaque de cédulas ou valores
-----------------------------------------------------------------------------
*/
/* Texto na cor vermelha. */
td.red {
/* color: #FF0000; */
color: #CC0000;
}
/* Texto na cor azul. */
td.blue {
/* color: #0000FF; */
color: #0000CC;
}
/* Cédula com cor ciza de fundo. */
td.shade {
background-color: #CCCCCC;
}
/* Linha embaixo. */
td.line {
border-bottom: 1px solid #000000;
}
/* Negrito. */
td.bold {
font-weight: bold;
}
/* Itálico. */
td.italic {
font-style: italic;
}
/*
-----------------------------------------------------------------------------
Títulos de sessões
-----------------------------------------------------------------------------
*/
h1 {
font-size:2.2em;
line-height:1.1em;
}
h2 {
font-size: 1.6em;
padding-top: 0.7em;
padding-bottom: 0.7em;
}
h3 {
font-size:1.3em;
}
h4 {
font-size:1.0em;
}
h5 {
font-size:0.9em;
}
h6 {
font-size:0.8em;
}
/*
-----------------------------------------------------------------------------
Links
-----------------------------------------------------------------------------
*/
a {
/* text-decoration: underline; */
text-decoration: none;
/* background-color: #F8F8F8; */
color: #007560;
}
a:visited {
/* color: #0075EE; */
color: rgb(50%, 0%, 50%);
}
/*
-----------------------------------------------------------------------------
Imagens
-----------------------------------------------------------------------------
*/
pre, img {
max-width: 100%;
}
/*
-----------------------------------------------------------------------------
Blocos de código/verbatim
-----------------------------------------------------------------------------
*/
/* Blocos de código criados com tripla crase. */
pre code {
/* margin-top: -0.75em; */
/* margin-bottom: -0.75em; */
/* margin-left: 3em; */
display: block;
padding: 0.5em;
/* padding-left: 0.75em; */
/* padding-right: 0.75em; */
/* padding-top: 0em; */
/* padding-bottom: 0em; */
/* background-color: #333333; */
/* border: 1px; */
/* font-size: 115%; */
line-height: 125%;
}
/* Código sem classe, inline e blocos de warning e error do R. */
code {
/* border: 1px solid #ccc; */
/* border-left: 2px dotted #ccc; */
/* border-right: 2px dotted #ccc; */
background-color: #E6E6E6;
}
/* Código de classe R, input, output, exceto warnings e errors. */
code[class] {
/* background-color: #F8F8F8; */
/* background-color: #E6E6E6; */
/* background-color: #EEEEEE; */
/* border: 1px; */
background-color: #F2F2F2;
}
/*
-----------------------------------------------------------------------------
Ambiente/bloco de parafrase ou quotation
-----------------------------------------------------------------------------
*/
blockquote {
color:#666666;
margin:0;
padding-left: 1em;
border-left: 0.5em #EEE solid;
}
/*
-----------------------------------------------------------------------------
Linhas horizontais.
-----------------------------------------------------------------------------
*/
hr {
height: 0px;
border-bottom: none;
border-top-width: 1px;
/* border-top-style: dotted; */
border-top-style: solid;
border-top-color: #999999;
}
hr.white {
border-top-color: #FFFFFF;
}
/*
-----------------------------------------------------------------------------
Caixas de alerta, notificação, erro, etc:
http://www.cssportal.com/blog/css-notification-boxes/
-----------------------------------------------------------------------------
*/
.alert-box {
color: #555;
border-radius: 5px;
/* font-family:Tahoma, Geneva, Arial, sans-serif; */
font-size: 14px;
/* padding:10px 10px 10px 36px; */
padding: 10px 10px 10px 20px;
margin: 10px;
}
.alert-box span {
font-weight:bold;
text-transform:uppercase;
}
.error {
background:#ffecec;
border:1px solid #f5aca6;
}
.success {
background:#e9ffd9;
border:1px solid #a6ca8a;
}
.warning {
background:#fff8c4;
border:1px solid #f2c779;
}
.notice {
background:#e3f7fc;
border:1px solid #8ed9f6;
}
/*
-----------------------------------------------------------------------------
Ainda não descobri para que servem as definições abaixo
-----------------------------------------------------------------------------
*/
@media print {
* {
background: transparent !important;
color: black !important;
filter:none !important;
-ms-filter: none !important;
}
body {
font-size:12pt;
max-width:100%;
}
a, a:visited {
text-decoration: underline;
}
hr {
visibility: hidden;
page-break-before: always;
}
pre, blockquote {
padding-right: 1em;
page-break-inside: avoid;
}
tr, img {
page-break-inside: avoid;
}
img {
max-width: 100% !important;
}
@page :left {
margin: 15mm 20mm 15mm 10mm;
}
@page :right {
margin: 15mm 10mm 15mm 20mm;
}
p, h2, h3 {
orphans: 3; widows: 3;
}
h2, h3 {
page-break-after: avoid;
}
}
/* ----------------------------------------------------------------------------- */
library(shiny)
library(xtable)
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
}
}
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)
})
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))
})
})
library(shiny)
library(xtable)
library(labestData, lib.loc = "/home/walmes/R/")
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"),
# 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(),
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
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/labestDataView.R
\name{labestDataView}
\alias{labestDataView}
\title{Shiny App para Visualização e Download dos Datasets}
\usage{
labestDataView()
}
\value{
Abre uma aplicação web com shiny.
}
\description{
Essa função abre uma interface \pkg{shiny} para
visualizar as tabelas de dados e consultar a documentação. Além
disso, tem um botão para salvar o dado em txt.
}
\section{Warning}{
Para funcionar, é necessário ter o pacote shiny
instalado. Para abrir a documentação dos datasets é necessário
informar o número da porta que o navegador usa
(\code{http://127.0.0.1:XXXXX}) para exibir a documentação em
html. Para ter esse número, peça a documentação de alguma
função antes de chamar a aplicação. Veja na seção exemplos como
fazer.
}
\examples{
\dontrun{
options(help.ports = 1111)
help(BanzattoQd1.2.3, help_type = "html")
help(package = "labestData", help_type = "html")
labestDataView()
}
}
\author{
Walmes Zeviani e Eduardo Ribeiro Jr.
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment