我制作了一个闪亮的应用程序,当我添加一个新的fluidRow
. 这是一个小例子
library(shinydashboard)
header <- dashboardHeader(title = 'Name')
sidebar <- dashboardSidebar()
body <- dashboardBody(
fluidRow(
box(widht = 12, title = 'Group', textOutput('group_name'))
),
fluidRow(
box(width = 4, title = 'Frim', textOutput('firm_name')),
box(width = 4, title = 'INN', textOutput('firm_inn')),
box(width = 4, title = 'Branch', textOutput('firm_branch'))
),
fluidRow(
box(status = 'primary', height = '250px', width = 4, title = 'name1', plotlyOutput('firm_limits_utiliz'), solidHeader = TRUE),
box(status = 'primary', height = '250px', width = 4, title = 'name2', plotlyOutput('firm_limits_remains'), solidHeader = TRUE),
box(status = 'warning', height = '250px', width = 4, title = 'name3', tableOutput('group_limits') , solidHeader = TRUE,
style = "overflow-x: scroll;")
) )
ui <- dashboardPage(body = body, header = header, sidebar = sidebar, skin = 'blue')
server <- function(input, output) {
output$group_name <- renderText({'Shell'})
output$firm_name <- renderText({'Shell ltd'})
output$firm_inn <- renderText({'770565479'})
output$firm_branch <- renderText({'Oil and Gas'})
output$firm_limits_utiliz <- renderPlotly({
fig <- plot_ly(
domain = list(x = c(0, 1), y = c(0, 1)),
value = 270,
# title = list(text = "Speed"),
type = "indicator",
mode = "gauge+number",
height = 197, width = 393)
fig <- fig %>%
layout(margin = list(l=20,r=30))
fig
})
output$group_limit_utiliz <- renderPlotly({
fig <- plot_ly(
domain = list(x = c(0, 1), y = c(0, 1)),
value = 270,
# title = list(text = "Speed"),
type = "indicator",
mode = "gauge+number",
height = 197, width = 393)
fig <- fig %>%
layout(margin = list(l=20,r=30))
fig
})
}
# Run the application
shinyApp(ui = ui, server = server)
如果我运行此代码,一切顺利。无花果图形显示在仪表板上。但!
当我添加一个新fluidRow
的无花果图消失。例如,让我为您提供body
一部分代码:
body <- dashboardBody(
fluidRow(
box(widht = 12, title = 'Group', textOutput('group_name'))
),
fluidRow(
box(width = 4, title = 'Firm', textOutput('firm_name')),
box(width = 4, title = 'INN', textOutput('firm_inn')),
box(width = 4, title = 'Branch', textOutput('firm_branch'))
),
fluidRow(
box(status = 'primary', height = '250px', width = 4, title = 'name1', plotlyOutput('firm_limits_utiliz'), solidHeader = TRUE),
box(status = 'primary', height = '250px', width = 4, title = 'name2', plotlyOutput('firm_limits_remains'), solidHeader = TRUE),
box(status = 'warning', height = '250px', width = 4, title = 'name3', tableOutput('group_limits') , solidHeader = TRUE,
style = "overflow-x: scroll;")
),
# Here i a new fluidRow
fluidRow(
box(status = 'primary', height = '250px', width = 4, title = 'name6', plotlyOutput('group_limit_utiliz'), solidHeader = TRUE),
box(status = 'primary', height = '250px', width = 4, title = 'name4', plotlyOutput('gtoup_limit_remains'), solidHeader = TRUE),
box(status = 'warning', height = '250px', width = 4, title = 'name5', tableOutput('group_limits') , solidHeader = TRUE,
style = "overflow-x: scroll;")
)
)
如您所见,有一个新的fluidRow
. 在这种情况下,fig
带有firm_limits_utiliz
id 的图消失了。怎么了?
如果您使用另一个变量名称创建输出副本,它会起作用:
#new fluidRow
fluidRow(
box(status = 'primary', height = '250px', width = 4, title = 'name6', plotlyOutput('group_limit_utiliz2'), solidHeader = TRUE),
box(status = 'primary', height = '250px', width = 4, title = 'name4', plotlyOutput('gtoup_limit_remains2'), solidHeader = TRUE),
box(status = 'warning', height = '250px', width = 4, title = 'name5', tableOutput('group_limits2') , solidHeader = TRUE,
style = "overflow-x: scroll;")
)
输出:
output$group_limit_utiliz2 <- renderPlotly({
fig2 <- plot_ly(
domain = list(x = c(0, 1), y = c(0, 1)),
value = 270,
# title = list(text = "Speed"),
type = "indicator",
mode = "gauge+number",
height = 197, width = 393)
fig2 <- fig2 %>%
layout(margin = list(l=20,r=30))
fig2
})
请注意,我为所有变量名称添加了2,但其他所有内容都相同。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句