File: histogram.R

package info (click to toggle)
r-cran-shinystan 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,172 kB
  • sloc: sh: 15; makefile: 7
file content (49 lines) | stat: -rw-r--r-- 1,241 bytes parent folder | download | duplicates (2)
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
# histogram
hist_transform_x <- eventReactive(input$hist_transform_x_go > 0,
                                  input$hist_transform_x)

histogram_plot <- reactive({
  validate(
    need(input$param, message = FALSE),
    need(!is.null(input$hist_chain), message = FALSE)
  )
  chain <- input$hist_chain
  if (is.na(chain))
    chain <- 0
  binwd <- input$hist_binwd
  if (is.na(binwd))
    binwd <- 0
  
  do.call(
    ".param_hist",
    args = list(
      param       = input$param,
      dat         = par_samps_post_warmup(),
      chain       = chain,
      binwd       = binwd,
      fill_color  = input$hist_fill_color,
      line_color  = input$hist_line_color,
      transform_x = hist_transform_x()
    )
  )
})

output$hist_plot_out <- renderPlot({
  x <- histogram_plot()
  suppress_and_print(x)
}, bg = "transparent")

# download plot
output$download_histogram <- downloadHandler(
  filename = 'shinystan-histogram-gg.RData',
  content = function(file) {
    shinystan_histogram_gg <- histogram_plot()
    save(shinystan_histogram_gg, file = file)
  }
)
output$save_pdf_histogram = downloadHandler(
  filename = "shinstan-histogram.pdf",
  content = function(file) {
    ggsave(file, plot = histogram_plot(), device = pdf)
  }
)