【发布时间】:2021-10-15 14:10:47
【问题描述】:
我目前正在开发一个带有滑块的 Shiny 仪表板,该滑块使用滑块输入输出给定波动率值的股票、黄金和白银的最佳投资组合权重。在给定滑块输入的情况下,我已经能够通过动态文本输出输出值,但我无法弄清楚如何将这些值转换为图形,因为 Shiny 中的文本输出似乎需要一个函数。如何使用从slidervalues() 获得的值向此代码添加饼图?它输出一个包含 5 个数值的列表,现在我想在饼图中绘制前 3 个数值:
library(shiny)
shinyUI(fluidPage(
headerPanel(title = "Volatility Slider"),
sidebarLayout(
sidebarPanel(
sliderInput("Risk","Volatility", 0, 0.24, 0.12)
),
mainPanel(
textOutput("Output")
)
)
))
server <- function(input, output) {
sliderValues <- reactive({
#This part finds the optimal portfolio using CAPM(which is found in a different script).
custom <- three_assets %>%
filter(sd_p > input$Risk,
sd_p < input$Risk+0.0001)
max_er_custom <- custom[custom$er_p == max(custom$er_p)]
toString(max_er_custom)
})
output$Output <- renderText({
sliderValues()
})
}
【问题讨论】: