Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
闪亮-如何使用ggiraph_R_Shiny_Ggiraph - Fatal编程技术网

闪亮-如何使用ggiraph

闪亮-如何使用ggiraph,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$

我的数据集如下

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)

这是一个使用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)
库(闪亮)
图书馆(dplyr)
图书馆(GG2)
图书馆(ggiraph)
用户界面
    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)