【发布时间】:2017-07-05 11:53:11
【问题描述】:
我正在尝试在我的 Shiny 应用程序中创建一个 rBokeh 图作为输出,在 UI 中使用 rbokehOutput('plot') 和
output$plot <- renderRbokeh({
figure() %>%
ly_hexbin(x,y)
})
在服务器部分。我希望绘图的大小在某种意义上是动态的,它应该动态调整大小以填充整个绘图窗口。我一直在使用 height 和 width 参数,在 ui 和服务器部分,但无法使其工作;我还尝试在服务器部分使用sizing_mode = "stretch_both"。当我在没有 Shiny 的 RStudio 中显示绘图时,绘图也不会填满整个绘图窗口,它保持其方形和纵横比。我希望它表现得像一个普通的 R 绘图,即当我放大绘图窗口时,绘图会自动调整大小以填充整个窗口。我找到了this link,但它只处理 Python 实现。理想情况下,我希望 Shiny 中的高度固定为 500 像素,宽度根据浏览器的(大小)动态变化。
最小的工作示例:
library(shiny)
library(rbokeh)
ui <- fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
sliderInput('numpoint', 'Number of points to plot', min = 10, max = 1000, value = 200)
),
mainPanel(
rbokehOutput('plot', width = "98%", height = "500px")
)
)
)
server <- function(input, output) {
output$plot <- renderRbokeh({
x <- seq(1, 100, length = input$numpoint)
y <- rnorm(input$numpoint, sd = 5)
figure() %>%
ly_hexbin(x,y)
})
}
shinyApp(ui, server)
更新的 MWE:
library(shiny)
library(rbokeh)
ui <- fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
sliderInput('numpoint', 'Number of points to plot', min = 10, max = 1000, value = 200)
),
mainPanel(
fluidRow(
column(12,
rbokehOutput('plot', height = "800px")
)
),
fluidRow(
column(12,
plotOutput('plot1', height = "800px")
)
)
)
)
)
server <- function(input, output) {
output$plot <- renderRbokeh({
x <- seq(1, 100, length = input$numpoint)
y <- rnorm(input$numpoint, sd = 5)
figure(width = 1800, height = 800) %>%
ly_hexbin(x,y)
})
output$plot1 <- renderPlot({
x <- seq(1, 100, length = input$numpoint)
y <- rnorm(input$numpoint, sd = 5)
plot(x,y)
})
}
shinyApp(ui, server)
【问题讨论】: