如何显示一系列的 Jmeter 在shinyapp使用shinydashboard与一个固定数量的 Jmeter 每行

tjrkku2a  于 2023-01-06  发布在  其他
关注(0)|答案(1)|浏览(111)

我想以网格的方式显示一系列刻度盘(圆形 Jmeter )。我最好将大量 Jmeter 压缩在一起a-比如说,6个或12个 Jmeter 排成一行,然后我们将查看多行。我发现R包plotlyplot_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)
h79rfbju

h79rfbju1#

Edit:这里是使用splitLayout的另一种方法。请注意,plotlyOutput为我们提供了一个height参数:

library(shiny)
library(plotly)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    fluidPage(
      fluidRow(do.call(splitLayout, c(lapply(1:4, function(i) {
        plotlyOutput(paste0("gauge_", i), height = "275px")
      }), cellWidths = "25%"))),
      fluidRow(do.call(splitLayout, c(lapply(5:8, function(i) {
        plotlyOutput(paste0("gauge_", i), height = "275px")
      }), cellWidths = "25%")), style = "margin-top:10px")
    )
  )
)

server <- function(input, output) {
  data <- reactive({
    data.frame(
      value = sample(0:100, 8),
      color = sample(c("#FF0000", "#00FF00", "#0000FF", "#FFFF00", "#00FFFF", "#FF00FF"), 8, replace = TRUE)
    )
  })
  
  lapply(1:8, function(i) {
    output[[paste0("gauge_", i)]] <- renderPlotly({
      plot_ly(
        type = "indicator",
        mode = "gauge+number",
        value = data()[i, "value"],
        domain = c(0, 100),
        title = list(text = paste("Gauge", i)),
        gauge = list(color = data()[i, "color"])
      ) %>% layout(autosize = F, margin =  list(
        l = 50,
        r = 50,
        b = 0,
        t = 10,
        pad = 4
      ))
    })
  })
}

shinyApp(ui, server)

只需使用shinydashboard::box()width参数,也可以检查splitLayout()或库(gridlayout):

library(shiny)
library(plotly)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    fluidRow(
      lapply(1:4, function(i) {
        box(
          plotlyOutput(paste0("gauge_", i)), width = 3
        )
      })
    ),
    fluidRow(
      lapply(5:8, function(i) {
        box(
          plotlyOutput(paste0("gauge_", i)), width = 3
        )
      })
    )
  )
)

server <- function(input, output) {
  data <- reactive({
    data.frame(
      value = sample(0:100, 8),
      color = sample(c("#FF0000", "#00FF00", "#0000FF", "#FFFF00", "#00FFFF", "#FF00FF"), 8, replace = TRUE)
    )
  })
  
  lapply(1:8, function(i) {
    output[[paste0("gauge_", i)]] <- renderPlotly({
      plot_ly(
        type = "indicator",
        mode = "gauge+number",
        value = data()[i, "value"],
        domain = c(0, 100),
        title = list(text = paste("Gauge", i)),
        gauge = list(color = data()[i, "color"])
      )
    })
  })
}

shinyApp(ui, server)

相关问题