[英]How to adjust a Shiny Dashboard's size to fit different screen sizes?
I have a shiny app with this basic layout that I wrote on my desktop computer where it fits the screen perfectly.我有一个 shiny 应用程序,它具有我在台式计算机上编写的基本布局,它非常适合屏幕。 However, when running the app on my notebook it'll only show the top left boxes- so the app is way to big for the screen.
但是,在我的笔记本上运行该应用程序时,它只会显示左上角的框 - 因此该应用程序对于屏幕来说太大了。 Upon pressing Ctrl - it will obviously become smaller but still about a quarter of the bottom row is cut off and pressing Ctrl - again the app only fills half the screen.
按 Ctrl 后 - 它显然会变小,但仍然有大约四分之一的底行被切断并按 Ctrl - 应用程序再次只填满屏幕的一半。 Now I want to provide this app as a feedback tool for my study participants and it's safe to assume they will access it from different sized screens aswell.
现在我想提供这个应用程序作为我的研究参与者的反馈工具,并且可以安全地假设他们也会从不同尺寸的屏幕访问它。 So I was wondering if there was any way to automatically adjust the box sizes to the size of the screen, no matter its size.
所以我想知道是否有任何方法可以自动将框大小调整为屏幕大小,无论其大小如何。 I came up with the idea that maybe the mistake was setting the box heights to a fixed value (ie height = 300), but my attempt of changing it to 30% revealed that that's not a thing you can do.
我想出了一个想法,也许错误是将框高度设置为固定值(即高度 = 300),但我将其更改为 30% 的尝试表明这不是你可以做的事情。 I read over some CSS-related questions on this site aswell but didn't find anything that worked here either (I know very little CSS though, so I might have missed something there).
我也在这个网站上阅读了一些与 CSS 相关的问题,但也没有找到任何有用的东西(虽然我知道的很少 CSS,所以我可能在那里遗漏了一些东西)。 Does anyone have an idea how to fix that issue?
有谁知道如何解决这个问题?
library(shiny)
library(shinydashboard)
body <- dashboardBody( tags$head(tags$style(HTML('
.box {margin-top: 2px;margin-left: 0px; margin-right: 0px; margin-bottom:2px;padding:-10px}
div {padding: 0 !important;}'
))),
fluidRow(
box( title = "Mediennutzung", background = "green", solidHeader = TRUE, height=300
),
box(background = "green", title= "Verteilung", height = 300
)
),
fluidRow(
box(
title = "Schlaf", width = 4, solidHeader = TRUE, status = "success",
height= 350
),
box(
title = "Vergleich mit anderen", width = 5, solidHeader = TRUE, status = "success"
, height= 350
),
box(
title = "Wohlbefinden", width = 3, solidHeader = TRUE, status = "success",
"Ergebnis DASS und PMH, Einordnung, Vergleich mit der Stichprobe", height= 350
)
),
fluidRow(
box(
width = 4, background = "green", title = "Warum ist das wichtig?",
height= 135
),
box(
title = "Warum ist das wichtig?", width = 5, background = "green",
height= 135
),
box(
title = "Warum ist das wichtig?",width = 3, background = "green",
height= 135
)
),
fluidRow(
box(
width = 4, background = "green", title= "Zusammenhang zur Mediennutzung",
"Schlaf mag oder mag nicht mit der Mediennutzung zusammenhngen", height= 125
),
box(
title = "Zusammenhang zur Mediennutzung", width = 5, background = "green",
"Mal gucken", height= 125
),
box(
title = "Zusammenhang zur Mediennutzung",width = 3, background = "green",
"TBC", height= 125
)
)
)
# here the actual app starts
ui <- dashboardPage(
dashboardHeader(title = "Deine Ergebnisse"),
dashboardSidebar(textInput(inputId = "Code", label= HTML("<b>Willkommen auf unserer Auswertungsseite! Bitte gib hier deinen persönlichen Code ein.</b><br><em>(Gross- oder Kleinschreibung ist egal) </em>"), placeholder= "z.B. 01ABAB01"),
actionButton (inputId = "Button", label = "Meine Ergebnisse anzeigen"),
box(width = 12, background= "blue", HTML(
"TEXT"))
),
body)
server <- function(input, output) {}
shinyApp(ui=ui, server=server)
This solution might help you.此解决方案可能对您有所帮助。 I'm not very well versed in CSS so I don't think it is the most elegant way but it works.
我不是很精通 CSS 所以我不认为这是最优雅的方式但它有效。 Try nesting your
shinydashboard::box()
's in a div()
with class that changes the size based on screensize.尝试将
shinydashboard::box()
嵌套在带有 class 的div()
中,根据屏幕大小更改大小。
div(class = "col-sm-12 col-md-12 col-lg-4",
shinydashboard::box(width = 12,
title = "Left or Upper Box",
p("This box will be 4 wide on large screen, and 12 wide on medium and small screens")
)
),
div(class = "col-sm-12 col-md-12 col-lg-8",
shinydashboard::box(width = 12,
title = "Right or Lower Box",
p("This box will be 8 wide on large screen, and 12 wide on medium and small screens")
)
),
The downside of this approach is that there is extra padding either side of the boxes.这种方法的缺点是框的两边都有额外的填充。 There will be a way to remove this with some better CSS I bet.
我打赌会有更好的 CSS 来删除它。 NOTE that the widths within the boxes themselves should be 12 so that they fill the
div()
at all widths.请注意,框内的宽度应为 12,以便它们以所有宽度填充
div()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.