我正在寻求有关我闪亮的仪表板问题的帮助。本质上,我有一个 selectInput 菜单,但是希望能够选择多个变量并将它们全部绘制在同一个图表上。
目前我可以让它在 plot.ly 图上绘制一个选定的变量,但是即使我选择了多个变量,它仍然只会绘制选定的第一个变量:
此外,当应用程序首次运行时,我会收到此错误,直到我手动选择一个变量:
这是迄今为止我正在使用的代码的简化版本:
global_indices <- read_excel("Market_Data.xlsx",
sheet = 4,
col_names = FALSE,
skip = 5)
global_indices_clean <- global_indicies[,c(1,3,7,9,13,21,23)]
colnames(global_indices_clean) <- c("Date", "Australia", "US", "UK", "Germany", "Japan", "Hong_Kong")
global_indices_2y2 <- global_indices_clean %>% filter(between(Date, now() - years(2), now()))
header <- dashboardHeader(
title = "Dashboard"
)
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Global Indices",
tabName = "global_indices")
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "global_indices",
fluidRow(
box(plotlyOutput("plot_3"), title = "Developed indices", status = "primary", width = 4, ""),
box(plotlyOutput(""), title = "", status = "primary", width = 4, ""),
box(plotlyOutput(""), title = "", status = "primary", width = 4, "")
),
fluidRow(
box(selectInput("global_indices_input", "Indices",
choices =
list("Australia" = "Australia",
"US" = "US",
"UK" = "UK",
"Germany" = "Germany",
"Japan" = "Japan",
"Hong Kong" = "Hong_Kong"),
multiple = TRUE),
width = 4)
)
)
)
)
ui <- dashboardPage(
header,
sidebar,
body
)
server <- function(input, output) {
output$plot_3 <- renderPlotly({
plot_3 <- plot_ly(
global_indices_2y2, x = global_indices_2y2$Date, y = ~get(input$global_indices_input), type="scatter", mode="lines"
)
})
}
shinyApp(ui, server)
我无法提供数据集本身,但以下是其中的一小部分:
> str(global_indices_2y2)
'data.frame': 478 obs. of 7 variables:
$ Date : POSIXct, format: "2018-01-29" "2018-01-30" "2018-01-31" "2018-02-01" ...
$ Australia: num 107 106 106 107 108 ...
$ US : num 113 112 112 112 110 ...
$ UK : num 104 103 102 102 101 ...
$ Germany : num 103.9 102.9 102.8 101.4 99.7 ...
$ Japan : num 116 114 113 115 114 ...
$ Hong_Kong: num 120 118 119 118 118 ...
在过去的几天里,我在这里阅读了数十个线程,但是它们似乎都关注围绕多个 selectInput 参数的问题,而不是单个 selectInput 需要能够选择和显示多个输出的问题。
您能提供的任何帮助将不胜感激!