修订版 | 878ca162b805294e9f2a4787be8d4d79d5abfdfb (tree) |
---|---|
时间 | 2022-04-01 21:46:26 |
作者 | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
A self contained example about how to use latex in shiny + plotly.
@@ -0,0 +1,34 @@ | ||
1 | +library(shiny) | |
2 | +library(plotly) | |
3 | +library(tidyverse) | |
4 | + | |
5 | +set.seed(1234) | |
6 | + | |
7 | +x <- runif(2000) | |
8 | + | |
9 | +df_frag_norm <- tibble(n1_norm = x) | |
10 | + | |
11 | +ui <- fluidPage( | |
12 | + withMathJax(), | |
13 | + plotlyOutput("myplot1") | |
14 | +) | |
15 | + | |
16 | +server <- function(input, output) { | |
17 | + output$myplot1 <- renderPlotly({ | |
18 | + fig <- plot_ly( | |
19 | + df_frag_norm, | |
20 | + x = ~ n1_norm, | |
21 | + ## y = ~decessi_giornalieri, | |
22 | + type = 'histogram', | |
23 | + xbins = list(size = 0.05) | |
24 | + ) %>% | |
25 | + layout(bargap = 0.1, | |
26 | + xaxis = list( | |
27 | + range = c(0, 1), | |
28 | + title = TeX("n_1/(n_1+n_2)") | |
29 | + )) | |
30 | + }) | |
31 | + | |
32 | +} | |
33 | + | |
34 | +shinyApp(ui, server) |