gpt4 book ai didi

r - Shiny - 如何使用 ggiraph

转载 作者:行者123 更新时间:2023-12-02 08:17:57 26 4
gpt4 key购买 nike

我的数据集如下....

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com