[英]How to adjust the width of sidebarPanel without affect subsequent sidebarPanel widths in R Shiny
[英]How to adjust the size of my sidebarPanel in Shiny in R?
我只是不知道如何調整我的sidebarPanel
,有人可以幫助我嗎? 這是我的代碼:
library(ggplot2)
library(Cairo) # For nicer ggplot2 output when deployed on Linux
library(shiny)
mtcars2 <- mtcars[, c("mpg", "cyl", "disp", "hp", "wt", "am", "gear")]
ui <- fluidPage(
fluidRow(
column(width = 4, class = "well",
h4("Brush and double-click to zoom"),
plotOutput("plot1", height = 300, width = 500,
click = "plot1_click",
dblclick = "plot1_dblclick",
brush = brushOpts(
id = "plot1_brush",
resetOnNew = TRUE)))),
fluidRow(
column(width = 6,
h4("Brushed points"),
verbatimTextOutput("brush_info"))))
server <- function(input, output) {
# -------------------------------------------------------------------
# Single zoomable plot (on left)
ranges <- reactiveValues(x = NULL, y = NULL)
output$plot1 <- renderPlot({
ggplot(mtcars2, aes(wt, mpg)) + geom_point() +
coord_cartesian(xlim = ranges$x, ylim = ranges$y, expand = FALSE)})
# When a double-click happens, check if there's a brush on the plot.
# If so, zoom to the brush bounds; if not, reset the zoom.
observeEvent(input$plot1_dblclick, {
brush <- input$plot1_brush
if (!is.null(brush)) {
ranges$x <- c(brush$xmin, brush$xmax)
ranges$y <- c(brush$ymin, brush$ymax)}
else {
ranges$x <- NULL
ranges$y <- NULL
}})
output$brush_info <- renderPrint({
brushedPoints(mtcars2, input$plot1_brush)})
}
shinyApp(ui, server)
我應該在我的ui
中添加什么,以便我的sidebarPanel
可以變得更寬或適合整個屏幕?
因為它看起來已經太小了。
還有設計布局的建議嗎?
非常感謝。
如果從 plotOutput 中刪除高度和寬度參數,它將允許列響應 web 頁面的寬度。 因此,如果您設置 column(width = 12, ...) 它應該適合整個屏幕。 與您的“拉絲點”列相同(如果需要)
例如,這將使兩個元素都適合整個頁面:
library(ggplot2)
library(shiny)
mtcars2 <- mtcars[, c("mpg", "cyl", "disp", "hp", "wt", "am", "gear")]
ui <- fluidPage(
fluidRow(
column(width = 12, class = "well",
h4("Brush and double-click to zoom"),
plotOutput("plot1",
click = "plot1_click",
dblclick = "plot1_dblclick",
brush = brushOpts(
id = "plot1_brush",
resetOnNew = TRUE)))),
fluidRow(
column(width = 12,
h4("Brushed points"),
verbatimTextOutput("brush_info"))))
server <- function(input, output) {
# -------------------------------------------------------------------
# Single zoomable plot (on left)
ranges <- reactiveValues(x = NULL, y = NULL)
output$plot1 <- renderPlot({
ggplot(mtcars2, aes(wt, mpg)) + geom_point() +
coord_cartesian(xlim = ranges$x, ylim = ranges$y, expand = FALSE)})
# When a double-click happens, check if there's a brush on the plot.
# If so, zoom to the brush bounds; if not, reset the zoom.
observeEvent(input$plot1_dblclick, {
brush <- input$plot1_brush
if (!is.null(brush)) {
ranges$x <- c(brush$xmin, brush$xmax)
ranges$y <- c(brush$ymin, brush$ymax)}
else {
ranges$x <- NULL
ranges$y <- NULL
}})
output$brush_info <- renderPrint({
brushedPoints(mtcars2, input$plot1_brush)})
}
shinyApp(ui, server)
可能會添加到您的 UI 中的是使您的 UI 元素居中。 您可以通過簡單地在 UI 元素之前添加空列並讓 shiny 處理屏幕響應(而不是自定義 CSS)來做到這一點:
library(ggplot2)
library(shiny)
mtcars2 <- mtcars[, c("mpg", "cyl", "disp", "hp", "wt", "am", "gear")]
ui <- fluidPage(
fluidRow(
column(width=3),
column(width = 6, class = "well",
h4("Brush and double-click to zoom"),
plotOutput("plot1",
click = "plot1_click",
dblclick = "plot1_dblclick",
brush = brushOpts(
id = "plot1_brush",
resetOnNew = TRUE)))),
fluidRow(
column(width=3),
column(width = 6,
h4("Brushed points"),
verbatimTextOutput("brush_info"))))
server <- function(input, output) {
# -------------------------------------------------------------------
# Single zoomable plot (on left)
ranges <- reactiveValues(x = NULL, y = NULL)
output$plot1 <- renderPlot({
ggplot(mtcars2, aes(wt, mpg)) + geom_point() +
coord_cartesian(xlim = ranges$x, ylim = ranges$y, expand = FALSE)})
# When a double-click happens, check if there's a brush on the plot.
# If so, zoom to the brush bounds; if not, reset the zoom.
observeEvent(input$plot1_dblclick, {
brush <- input$plot1_brush
if (!is.null(brush)) {
ranges$x <- c(brush$xmin, brush$xmax)
ranges$y <- c(brush$ymin, brush$ymax)}
else {
ranges$x <- NULL
ranges$y <- NULL
}})
output$brush_info <- renderPrint({
brushedPoints(mtcars2, input$plot1_brush)})
}
shinyApp(ui, server)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.