我正在使用shinydashboard
包做一个闪亮的仪表板。正如您在附带的图像中看到的那样,使用rCharts和HighCharts库完成的图表并未使用Box的所有空间。我想知道是否有人知道如何使用盒子的所有空间。请参阅附带的代码:
## app.R ##
library(shinydashboard)
library(rCharts)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
fluidRow(
tags$head(tags$style('.col-sm-6 {padding-left: 0px; padding-right: 0px ;}')),
box(status = "primary", width = 3, showOutput("plotAtmosphere", "Highcharts"))
)
)
)
server <- function(input, output) {
output$plotAtmosphere = renderChart({
a <- rHighcharts:::Chart$new()
d <- data.frame(label = c("Negative", "Positive"), value = c(30, 70))
a$title(text = "")
# a <- hPlot(value ~ label, data = d, type = 'pie')
a$data(x = c("Negative","Positive"), y = c(30, 70), type = "pie", name = "Amount")
a$plotOptions(pie = list(innerSize = "90%",
startAngle = -90, endAngle = 90, center = list("50%", "100%"),dataLabels = list(enabled = F)))
a$exporting(enabled = F)
a$chart(height = 150)
return(a) })
}
shinyApp(ui, server)
答案 0 :(得分:2)
这非常复杂,但你必须将另一个参数传递给你的服务器()功能:
server <- function(input, output, session)
然后使用clientData中的一个会话变量动态调整图表大小:
output$hexchart<-renderChart2({
h1 <- Highcharts$new()
h1$chart(type = "spline")
h1$series(data = c(1, 3, 2, 4, 5, 4, 6, 2, 3, 5, NA), dashStyle = "longdash")
h1$series(data = c(NA, 4, 1, 3, 4, 2, 9, 1, 2, 3, 4), dashStyle = "shortdot")
h1$legend(symbolWidth = 80)
h1$set(width = session$clientData$output_plot1_width) #dynamically resize with session variable
return(h1)
})
其中plot1是在ui中插入的虚拟图:
box(width = 12, height = 450, solidHeader = FALSE, status = "primary",
plotOutput("plot1", height = "1px"),
showOutput("hexchart","highcharts")
)
答案 1 :(得分:0)
添加CSS:
## app.R ##
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(),
dashboardBody(
# Boxes need to be put in a row (or column)
fluidRow(
tags$head(tags$style('.col-sm-6 {padding-left: 0px; padding-right: 0px ;}')),
box(plotOutput("plot1", height = 250)),
box(
title = "Controls",
sliderInput("slider", "Number of observations:", 1, 100, 50)
)
)
)
)
server <- function(input, output) {
set.seed(122)
histdata <- rnorm(500)
output$plot1 <- renderPlot({
data <- histdata[seq_len(input$slider)]
hist(data)
})
}
shinyApp(ui, server)