[英]How to adapt the height of an HTML widget to the height of the window in R Shiny?
How to adapt it so that it can be correctly rendered on different screens?如何对其进行适配,使其能够在不同的屏幕上正确呈现? (
height = "100%"
and height = "auto"
don't work) (
height = "100%"
和height = "auto"
不起作用)
I have to add text that is not code I have to add text that is not code I have to add text that is not code I have to add text that is not code I have to add text that is not code我必须添加非代码文本 我必须添加非代码文本 我必须添加非代码文本 我必须添加非代码文本 我必须添加非代码文本
[EDIT] Reprex below [编辑] 下面的 Reprex
RequiredLibraries <- c("data.table", "visNetwork", "shiny")
RequiredLibraries2Install <- RequiredLibraries[!(RequiredLibraries %in% installed.packages()[, "Package"])]
if(length(RequiredLibraries2Install)) install.packages(RequiredLibraries2Install, dependencies = TRUE)
lapply(RequiredLibraries, library, character.only = TRUE)
ui <- fluidPage(
titlePanel(windowTitle = "Application Title", title = "Application Title"),
sidebarLayout(
sidebarPanel(
h4("Year End"),
#hr(),
selectInput(inputId = "YE", label = "Year End", choices = 2016:2020, selected = c(2018), multiple = FALSE, selectize = FALSE),
width = 2
),
mainPanel(
# Freeze the main (on the right) panel and leave the sidebar (on the left) panel scrollable
style = "position:fixed;left:17%;",
tabsetPanel(type = "tabs",
tabPanel("Network",
visNetworkOutput(outputId = "Network", width = "100%", height = "75vh")
),
tabPanel(actionLink(inputId = "Download.Network.Data", label = "Download current network data", icon = icon(name = "download", class = NULL, lib = "font-awesome"))
)
),
width = 10
)
)
)
server <- function(input, output, session)
{
GenerateNetwork <- reactive({
# Taken from https://datastorm-open.github.io/visNetwork/edges.html
Links <- data.frame(from = sample(1:10, 8), to = sample(1:10, 8),
# add labels on edges
label = paste("Edge", 1:8),
# length
length = c(100, 500),
# width
width = c(4, 1),
# arrows
arrows = c("to", "from", "middle", "middle;to"),
# dashes
dashes = c(TRUE, FALSE),
# tooltip (html or character)
title = paste("Edge", 1:8),
# smooth
smooth = c(FALSE, TRUE),
# shadow
shadow = c(FALSE, TRUE, FALSE, TRUE)
)
Nodes <- data.frame(id = 1:10, group = c("A", "B"))
visNetwork(Nodes, Links, width = "100%", height = "700px", main = "Network Title") %>%
visInteraction(navigationButtons = TRUE, keyboard = TRUE) %>%
visPhysics(stabilization = TRUE) %>%
#visLegend(addNodes = Legend.Nodes, addEdges = Legend.Links, useGroups = FALSE, width = 0.25, position = "right", main = "Network Legend", ncol = 1) %>%
visLayout(randomSeed = 123)
})
# Create the output Network
output$Network <- renderVisNetwork(GenerateNetwork())
}
shinyApp(ui = ui, server = server, enableBookmarking = "server")
Use the CSS unit vh
.使用 CSS 单位
vh
。 Eg 100vh
, that means 100% of the height of the viewport.例如
100vh
,表示视口高度的 100%。 You can also try fit-content
.您也可以尝试
fit-content
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.