关于 r:shiny – 如何使用 ggiraph

shiny - how to use ggiraph

我的数据集如下......

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
fund , sharpe , risk
abc , 1.5 , 7
def , 0 , 5

selectInput("n_breaks", label ="Risk Profile:", choices = c(1,2,3,4,5,6,7,8,9,10), selected = 7)

# Reactive
selectedData <- reactive

  a <- mydata %>% filter(risk==as.numeric(input$n_breaks) & sharpe > 0)


renderPlot

  ggplot(selectedData(), aes(x = sharpe, y = returns, tooltip = fund, data_id = fund, color=sd)) +  geom_point_interactive(size=1)

我试图在 renderplot 处运行以下代码,但闪亮失败了。请指教

1
ggiraph(code = {print(gg_point_3)}, tooltip_offx = 20, tooltip_offy = -10 )

这是一个使用 iris 数据集的示例。

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
    library(shiny)
    library(dplyr)
    library(ggplot2)
    library(ggiraph)


    ui <- shinyUI(fluidPage(


       titlePanel("Shiny & ggiraph"),


       sidebarLayout(
          sidebarPanel(
             selectInput("species",
                        "Select species:",
                         selected ="setosa",
                         choices = unique(levels(iris$Species))
                         )
          ),


          mainPanel(
                    ggiraphOutput("plotIris")
          )
       )
    ))


    server <- shinyServer(function(input, output) {
            filterIris <- reactive({
                    filter(iris, Species == input$species)
            })

            output$plotIris <- renderggiraph({
                    gg <- ggplot(filterIris(), aes(x = Sepal.Length, y = Petal.Length))
                    gg <- gg + geom_point_interactive(
                            aes(tooltip = filterIris()$Sepal.Length), size = 2)
                    ggiraph(code = print(gg))
            })

    })


    shinyApp(ui = ui, server = server)