File: interactiveTable.Rd

package info (click to toggle)
r-cran-htmltable 2.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,600 kB
  • sloc: javascript: 6,797; makefile: 2
file content (83 lines) | stat: -rw-r--r-- 3,198 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/interactiveTable.R
\name{interactiveTable}
\alias{interactiveTable}
\alias{interactiveTable.htmlTable}
\alias{knit_print.interactiveTable}
\alias{print.interactiveTable}
\title{An interactive table that allows you to limit the size of boxes}
\usage{
interactiveTable(
  x,
  ...,
  txt.maxlen = 20,
  button = getOption("htmlTable.interactiveTable.button", default = FALSE),
  minimized.columns = NULL,
  js.scripts = c()
)

\method{interactiveTable}{htmlTable}(
  x,
  ...,
  txt.maxlen = 20,
  button = getOption("htmlTable.interactiveTable.button", default = FALSE),
  minimized.columns = NULL,
  js.scripts = c()
)

\method{knit_print}{interactiveTable}(x, ...)

\method{print}{interactiveTable}(x, useViewer, ...)
}
\arguments{
\item{x}{The table to be printed}

\item{...}{The exact same parameters as \code{\link[=htmlTable]{htmlTable()}} uses}

\item{txt.maxlen}{The maximum length of a text}

\item{button}{Indicator if the cell should be clickable or if a button should appear with a plus/minus}

\item{minimized.columns}{Notifies if any particular columns should be collapsed from start}

\item{js.scripts}{If you want to add your own JavaScript code you can just add it here.
All code is merged into one string where each section is wrapped in it's own
\verb{<scrip></script>} element.}

\item{useViewer}{If you are using RStudio there is a viewer thar can render
the table within that is envoced if in \code{\link[base:interactive]{base::interactive()}} mode.
Set this to \code{FALSE} if you want to remove that  functionality. You can
also force the function to call a specific viewer by setting this to a
viewer function, e.g. \code{useViewer = utils::browseURL} if you want to
override the default RStudio viewer. Another option that does the same is to
set the \code{options(viewer=utils::browseURL)} and it will default to that
particular viewer (this is how RStudio decides on a viewer).
\emph{Note:} If you want to force all output to go through the
\code{\link[base:cat]{base::cat()}} the set \verb{[options][base::options](htmlTable.cat = TRUE)}.}
}
\value{
An htmlTable with a javascript attribute containing the code that is then printed
}
\description{
This function wraps the htmlTable and adds JavaScript code for toggling the amount
of text shown in any particular cell.
}
\examples{
library(magrittr)
# A simple output
long_txt <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum"
short_txt <- gsub("(^[^.]+).*", "\\\\1", long_txt)

cbind(rep(short_txt, 2),
      rep(long_txt, 2)) \%>\%
  addHtmlTableStyle(col.rgroup = c("#FFF", "#EEF")) \%>\%
  interactiveTable(minimized.columns = ncol(.),
                   header = c("Short", "Long"),
                   rnames = c("First", "Second"))
}