【发布时间】:2020-05-28 16:49:31
【问题描述】:
我在闪亮的网络应用程序中做这个项目。
我想在箱形图上添加一条中线。
这是我的代码
library(shiny)
library(plotly)
ui <- fluidPage(
mainPanel(
plotlyOutput("distPlot")
)
)
server <- function(input, output) {
output$distPlot <- renderPlotly({
date <- c("1990-01-13",
"1990-01-13",
"1990-01-13",
"1990-01-13",
"1990-01-13",
"1990-01-13",
"1990-01-13",
"1990-01-14",
"1990-01-14",
"1990-01-14",
"1990-01-14",
"1990-01-14",
"1990-01-14",
"1990-01-14",
"1990-01-15",
"1990-01-15",
"1990-01-16",
"1990-01-16",
"1990-01-16",
"1990-01-16",
"1990-01-16",
"1990-01-16",
"1990-01-17",
"1990-01-17",
"1990-01-17",
"1990-01-18",
"1990-01-18",
"1990-01-18",
"1990-01-18",
"1990-01-18",
"1990-01-18",
"1990-01-19",
"1990-01-19",
"1990-01-19",
"1990-01-19"
)
trend <- c("9.5",
"6.2",
"3.3",
"3.6",
"6.1",
"0.6",
"2.3",
"2.3",
"4.7",
"9.9",
"12",
"4.6",
"4.5",
"8",
"2.3",
"3.4",
"7.7",
"1.9",
"2",
"10.1",
"3.3",
"4.7",
"6.5",
"3.9",
"4.4",
"5.2",
"8.1",
"3.2",
"6.3",
"4.4",
"2.4",
"0.5",
"7.2",
"8.1",
"5.9"
)
mydata <- data.frame(trend ,date())
p <- plot_ly(mydata,x=date,y = trend , type = "box",showlegend = FALSE)%>%
layout(yaxis = list(title = 'trend')
)
p
})
}
# Run the application
shinyApp(ui = ui, server = server)
实际上我是从 csv 文件中导入数据(趋势和日期)。但我不知道如何在 stackoverflow 中上传文件,所以我认为创建数据框更适合重现。
在我的预期中。
我的阴谋
[再次创建以进行复制]
当我在我的数据中使用聚合时
【问题讨论】:
-
顺便说一句:您可以使用
dput(<your_variable_name>)的输出将数据复制到stackoverflow -
好的,我正在尝试。
-
刚刚看到你的earlier question。区别在哪里 -
shiny上下文? -
我使用 read.csv.sql 。
shiny仅适用于 query 中的 where 子句。我认为我之前的问题不好,它只有随机数据。 -
是的,你的答案可以做到。但我遇到了一些问题,我会更新有问题的
标签: r shiny plotly boxplot r-plotly