我想以网格的方式显示一系列刻度盘(圆形 Jmeter )。我最好将大量 Jmeter 压缩在一起a-比如说,6个或12个 Jmeter 排成一行,然后我们将查看多行。我发现R包plotly
的plot_ly()
有一些不错的 Jmeter 图。但是在相邻的小框中呈现这些plot_ly()
Jmeter 正成为一个挑战。
我试过shinydashboard::valueBox()
,但是这些值框只接受一个标量值,所以我不能在里面放一个绘图对象。
更新1:最后,我使用了标准的shinydashboard::box()
,但是如截图所示,量规太高了。框之间的填充物浪费了空间。量规也没有很好地居中。x1c 0d1x
**UPDATE 2:**当数据刷新时,绘制的图表会改变其大小(宽度/高度),因此我们需要添加参数:plot_ly()中的width = 250, height = 175
,也可以获得适当的更新。
创建了新的reprex shiny应用程序以查看新问题。屏幕1 -加载shiny应用程序时-一切正常。
屏幕2 -一旦数据刷新-全部消失。
下面是演示UI折叠问题的新reprex。
# reprex for stackoverflow
library(shiny)
library(plotly)
library(shinydashboard)
N <- 24
dt1 <- dt1 <- data.table(
value = rnorm(N,mean = 50),
barcolor = sample(c("red", "yellow", "aqua", "blue", "light-blue", "green"),size = N,replace = T)
)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tags$style(".recalculating { opacity: inherit !important; }"),
fluidPage(
fluidRow(do.call(splitLayout, c(lapply(1:6, function(i) {
plotlyOutput(paste0("gauge_", i), height = "175px")
}), cellWidths = "16%"))),
fluidRow(do.call(splitLayout, c(lapply(7:12, function(i) {
plotlyOutput(paste0("gauge_", i), height = "175px")
}), cellWidths = "16%")), style = "margin-top:10px"),
fluidRow(do.call(splitLayout, c(lapply(13:18, function(i) {
plotlyOutput(paste0("gauge_", i), height = "175px")
}), cellWidths = "16%")), style = "margin-top:10px"),
fluidRow(do.call(splitLayout, c(lapply(19:24, function(i) {
plotlyOutput(paste0("gauge_", i), height = "175px")
}), cellWidths = "16%")), style = "margin-top:10px")
)
)
)
server <- function(input, output, session) {
data <- reactiveVal(value = dt1)
observe({
invalidateLater(5000)
dt1 <- data.table(
value = round(rnorm(N,mean = 50,sd = 10),0),
barcolor = sample(c("red", "yellow", "aqua", "blue", "light-blue", "green"),size = N,replace = T)
)
data(dt1)
})
# data <- reactiveFileReader(10000,session = session,filePath = "~/JSW-VTPL/data/grid.csv",readFunc = fread)
lapply(seq_len(N), function(i) {
output[[paste0("gauge_", i)]] <- renderPlotly({
plot_ly(
title = list(text = paste("Gauge_",i)),
type = "indicator",
mode = "gauge+number",
value = data()[i, value],
domain = list(x = c(0, 1), y = c(0, 1)),
gauge =
list(
shape = "indicator",
axis = list(range = c(0,100)),
color = "grey",
bar = list(color = data()[i,barcolor]))
) %>%
layout(autosize = F, margin = list(
l = 50,
r = 50,
b = 0,
t = 10,
pad = 4
))
})
})
}
shinyApp(ui, server)
1条答案
按热度按时间h79rfbju1#
Edit:这里是使用
splitLayout
的另一种方法。请注意,plotlyOutput
为我们提供了一个height
参数:只需使用
shinydashboard::box()
的width
参数,也可以检查splitLayout()
或库(gridlayout):