r - Shiny - 如何使用 ggiraph

标签 r shiny ggiraph

我的数据集如下....

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 上运行下面的代码,但 shiny 失败了。请指教

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

最佳答案

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

    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)

关于r - Shiny - 如何使用 ggiraph,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40199178/

相关文章:

r - 微基准 : Pass a variable to the function

r - 更改 Shiny Action 按钮的形状

R Shiny ggiraph 和 d3heatmap 兼容性问题

r - `NextMethod()` 的内部工作原理

r - 编织 RMarkdown 文件时遇到问题

R Shiny : not sure why ggplot is failing

r - ggiraph图未出现在 Shiny 的应用程序中,但可在RStudio中使用

r - ggiraph交互图可以是R Shiny 窗口的大小吗?

r - 在数据框中查找连续值

r - 是否写入 "ui.R + server.R"或 "app.R"