Commit 3c7c0ddf authored by arsenij.ustjanzew's avatar arsenij.ustjanzew
Browse files

Changed the manpage description for boxplot.R and visualization_functions.R;

Extended flexibility of plotly_boxplot;
parent 07775413
#' Renders a boxplot
#'
#' @param object A \linkS4class{i2dash::i2dashboard} object.
#' @param x Numeric observations for the boxplot. In case of a named list, a dropdown menu will be provided in the interactive mode.
#' @param group_by A factor, by which observations can optionally be grouped. In case of a named list, a dropdown menu will be provided in the interactive mode.
#' @param title The title of the components junk.
#' @param x A vector with numerical values or a named list, which represents the observations for the boxplot (x-axis). In case of a named list, a dropdown menu will be provided in the interactive mode.
#' @param group_by (Optional) A vector with factorial values or a named list, which will be used for grouping the observations. In case of a named list, a dropdown menu will be provided in the interactive mode.
#' @param title (Optional) The title of the components junk.
#' @param title_x (Optional) The title of the x-axis.
#' @param title_group_by (Optional) The title of the y-axis.
#'
#' @return A string containing markdown code for the rendered component.
#' @export
......
......@@ -129,21 +129,22 @@
#' Render a box plot with plotly.
#'
#' @param df A dataframe containing the data fo the boxplot.
#' @param group_by A factor, by which observations can optionally be grouped.
#' @param x A named list with the observations for the boxplot.
#' @param group_by A list with factorial values, by which observations can optionally be grouped.
#' @param title_x A title that describes the observations.
#' @param title_group_by A title that describes the grouping factor.
#'
#' @return An object of class \code{plotly}.
#' @export
plotly_boxplot <- function(df, group_by = NULL, title_x = NULL, title_group_by = NULL){
if (is.null(group_by)) {
y <- NULL
} else {
y <- df[[2]]
}
x <- df[[1]]
plotly_boxplot <- function(df, ..., title_x = NULL, title_group_by = NULL){
# if (is.null(group_by)) {
# y <- NULL
# } else {
# y <- group_by[[1]]
# }
# x <- x[[1]]
plotly::plot_ly(x = x, y = y, type = "box", name = names(df[1])) %>%
plotly::plot_ly(..., type = "box") %>%
plotly::layout(xaxis = list(title = title_x, showline = T),
yaxis = list(title = title_group_by, showline = T, showticklabels = T),
showlegend = F)
......
......@@ -23,7 +23,11 @@ if(is.null(group_by)){
i2dash::embed_var(df)
# Render plot
i2dash.scrnaseq::plotly_boxplot(df = df, group_by = {{ env_id }}$group_by, title_x = {{ env_id }}$title_x, title_group_by = {{ env_id }}$title_group_by)
if(is.null(group_by)){
i2dash.scrnaseq::plotly_boxplot(df = df, x = df[[1]], y = NULL, name = names(df[1]), title_x = {{ env_id }}$title_x, title_group_by = {{ env_id }}$title_group_by)
} else {
i2dash.scrnaseq::plotly_boxplot(df = df, x = df[[1]], y = df[[2]], name = names(df[1]), title_x = {{ env_id }}$title_x, title_group_by = {{ env_id }}$title_group_by)
}
```
```{r, eval=is_shiny}
......@@ -85,7 +89,11 @@ output$downloadData_{{ env_id }} <- downloadHandler(
# Output
#
output$plot_{{ env_id }} <- plotly::renderPlotly(
i2dash.scrnaseq::plotly_boxplot(df = df_{{ env_id }}(), group_by = {{ env_id }}$group_by, title_x = {{ env_id }}$title_x, title_group_by = {{ env_id }}$title_group_by)
if(is.null({{ env_id }}$group_by)){
i2dash.scrnaseq::plotly_boxplot(df = df_{{ env_id }}(), x = df_{{ env_id }}()[[1]], y = NULL, name = names(df_{{ env_id }}()[1]), title_x = {{ env_id }}$title_x, title_group_by = {{ env_id }}$title_group_by)
} else {
i2dash.scrnaseq::plotly_boxplot(df = df_{{ env_id }}(), x = df_{{ env_id }}()[[1]], y = df_{{ env_id }}()[[2]], name = names(df_{{ env_id }}()[1]), title_x = {{ env_id }}$title_x, title_group_by = {{ env_id }}$title_group_by)
}
)
shiny::fillCol(flex = c(NA, 1),
......@@ -93,3 +101,5 @@ shiny::fillCol(flex = c(NA, 1),
plotly::plotlyOutput("plot_{{ env_id }}", height = "100%")
)
```
......@@ -10,11 +10,15 @@ boxplot(object, x, group_by = NULL, title = NULL, title_x = NULL,
\arguments{
\item{object}{A \linkS4class{i2dash::i2dashboard} object.}
\item{x}{Numeric observations for the boxplot. In case of a named list, a dropdown menu will be provided in the interactive mode.}
\item{x}{A vector with numerical values or a named list, which represents the observations for the boxplot (x-axis). In case of a named list, a dropdown menu will be provided in the interactive mode.}
\item{group_by}{A factor, by which observations can optionally be grouped. In case of a named list, a dropdown menu will be provided in the interactive mode.}
\item{group_by}{(Optional) A vector with factorial values or a named list, which will be used for grouping the observations. In case of a named list, a dropdown menu will be provided in the interactive mode.}
\item{title}{The title of the components junk.}
\item{title}{(Optional) The title of the components junk.}
\item{title_x}{(Optional) The title of the x-axis.}
\item{title_group_by}{(Optional) The title of the y-axis.}
}
\value{
A string containing markdown code for the rendered component.
......
......@@ -4,17 +4,18 @@
\alias{plotly_boxplot}
\title{Render a box plot with plotly.}
\usage{
plotly_boxplot(df, group_by = NULL, title_x = NULL,
title_group_by = NULL)
plotly_boxplot(df, ..., title_x = NULL, title_group_by = NULL)
}
\arguments{
\item{df}{A dataframe containing the data fo the boxplot.}
\item{group_by}{A factor, by which observations can optionally be grouped.}
\item{title_x}{A title that describes the observations.}
\item{title_group_by}{A title that describes the grouping factor.}
\item{x}{A named list with the observations for the boxplot.}
\item{group_by}{A list with factorial values, by which observations can optionally be grouped.}
}
\value{
An object of class \code{plotly}.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment