首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >闪亮--如何使用ggiraph

闪亮--如何使用ggiraph
EN

Stack Overflow用户
提问于 2016-10-23 11:18:31
回答 1查看 1.8K关注 0票数 2

我的数据集如下...

代码语言:javascript
复制
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失败了。请指教

代码语言:javascript
复制
ggiraph(code = {print(gg_point_3)}, tooltip_offx = 20, tooltip_offy = -10 )
EN

回答 1

Stack Overflow用户

发布于 2016-10-23 14:08:13

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

代码语言:javascript
复制
    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)
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40199178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档