beam_plot_panel_SERVER: Creating server for a Shiny module with plot and data.

Description Usage Arguments Details See Also Examples

View source: R/plot_panel.R

Description

Creates module server for tabset panel containing two tabs - with plot and an elegant table with data.

Usage

1
2
3
4
5
6
7
8
9
beam_plot_panel_SERVER(
  id,
  plot_out,
  table_out,
  plot_type = "geom_point",
  tt_content = NULL,
  tt_range = 5,
  helpfiles = "helpfiles"
)

Arguments

id

unique Id of tabset panel. The same ID as in the corresponding UI for a module

plot_out

Plot to display in tab. There will be provided an automatically generated tooltip compatible with the plot. The items from first mapping will be connected with tooltip.

table_out

Table to display in tab.

plot_type

Type of plot corresponding to the data from first mapping. Accepts either 'geom_point', 'geom_segment' or 'geom_col'. Default 'geom_point'.

tt_content

Optional. If NULL in the tooltip will be displayed names of columns with corresponding values from data. One can customize tooltip content adding parameter tt_content here. It should be a list of chosen_cols and row_text. To display some values from the data in the content one should reference to the relevant column from the chosen_cols and in row_text write appropriate type of that variable like in the function sprintf (for example '%s' in case when chosen variable is a character string).

tt_range

A number denoting maximum distance between hoover and objects on the plot. The row, whose distance to the hoover is less than tt_range will be selected from the whole data. Default 5.

helpfiles

A character string denoting directory to save empty help files. Default 'helpfiles'.

Details

Module's server involves a panel with two tabs. The first tab consists of displayed plot and three download buttons (png, svg and jpeg). There is also a compatible with plot tooltip obtained via beam_tooltip. The second tab consists of a table with two download buttons (Excel and CSV). The table table_out before displaying is formatted using dt_format. For both table and plot there are provided helpers.

See Also

To build Shiny module within a Shiny app using beam_plot_panel_SERVER see beam_plot_panel_UI.

Examples

 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
## Not run: 
ui <- fluidPage(title = "Example app",
             beam_plot_panel_UI("airquality_basic"),
             beam_plot_panel_UI("airquality_advanced",
                                tab_plot = "An advanced plot",
                                tab_table = "An elegant table for an advanced plot",
                                helpfiles = "custom_helpfiles"))

server <- function(input, output, session) {
   airquality_basic_plot <- reactive({
       ggplot(airquality, aes(x = Wind, y = Temp, col = as.character(Month))) +
       geom_point()
   })
   airquality_basic_data <- reactive({
       airquality
   })
   beam_plot_panel_SERVER("airquality_basic",
                          plot_out = airquality_basic_plot(),
                          table_out = airquality_basic_data())

   airquality_advanced_data <- reactive({
       df <- data.frame(aggregate(. ~ Month, airquality, function(x) c(mean = mean(x), sd = sd(x)))[, c(1, 5)])
       df[["Month"]] <- month.name[df[["Month"]]]
       data.frame(Month = df[["Month"]],
       Temp_mean = df$Temp[, 1],
       Error = df$Temp[, 2],
       Year = 1973)})

   airquality_advanced_plot <- reactive({
       ggplot(airquality_advanced_data(), aes(y = 0, yend = Temp_mean, x = Month, xend = Month)) +
       geom_segment() +
       geom_point(mapping = aes(x = Month, y = Temp_mean), size = 3) +
       geom_point() +
       ylab("average temperature")
   })
   beam_plot_panel_SERVER("airquality_advanced",
                          plot_out = airquality_advanced_plot(),
                          table_out = airquality_advanced_data(),
                          plot_type = "geom_segment",
                          tt_content = list(row_text = c("Date: %s %i",
                                                         "Average temperature: %f °F",
                                                         "Error: %f",
                                                         "Place: La Guardia Airport"),
                                            chosen_cols = c("Month",
                                                            "Year",
                                                            "Temp_mean",
                                                            "Error"))
                         )

}

## End(Not run)

BioGenies/shinydetails documentation built on March 1, 2021, 11:12 p.m.