[英]Is there a way to not set rhandsontable height to a huge value in order to have the dropdown menu correctly render?
運行本文底部的代碼會顯示一個帶有下拉選項的 rhandsontable。 使下拉菜單出現的唯一方法是設置一個非常大的表格高度,但這會產生將actionButton()
向下推的丑陋效果。 如果您注釋掉表格高度的行(在代碼中用# <<
注明),則actionButton()
位置會解析但表格下拉列表不再呈現,如下圖所示。 有沒有辦法讓下拉菜單覆蓋(或懸停)在它們下面呈現的任何對象,這樣您就不必求助於這種愚蠢的桌面高度?
一個解決方案可能是將actionButton()
移到頂部,但在更完整的應用程序中,這是為了有一系列操作按鈕,這些按鈕有條件地在它們下面呈現重要對象,因此將actionButton()
移到頂部是不可行的. 它必須留在桌子下面。
插圖:
代碼:
library(shiny)
library(rhandsontable)
ui <- fluidPage(br(),
mainPanel(
rHandsontableOutput("Tbl"),br(),br(),
actionButton("add", "Add column"),
)
)
server <- function(input, output) {
DF <- reactiveVal(
data.frame(
'Series 1' = NA_character_,
stringsAsFactors = FALSE,
row.names = c("Select option"),
check.names = FALSE
)
)
observeEvent(input$Tbl,{DF(hot_to_r(input$Tbl))})
output$Tbl <- renderRHandsontable({
select_option <- c(NA_character_, "A","B","C","D","E","F","G","H","I","J","K")
tmp <- rhandsontable(
DF(),
rowHeaderWidth = 200,
selectCallback = TRUE,
height = 300 # << comment this line out to correctly position the action button
) %>%
hot_cols(colWidths = 100) %>%
hot_col("Series 1",
allowInvalid = FALSE,
type = "dropdown",
source = NA_character_,
readOnly = TRUE
)
tmp <- hot_col(tmp,
col = names(DF()),
allowInvalid = FALSE,
type = "dropdown",
source = select_option
) %>%
hot_cell(row = input$Tbl_select$select$r, col = "Series 1", readOnly = FALSE)
tmp
})
observeEvent(input$add, {
newCol <- data.frame('Series 1' = NA_character_,stringsAsFactors = FALSE)
names(newCol) <- paste("Series", ncol(hot_to_r(input$Tbl)) + 1)
DF(cbind(DF(), newCol))
})
}
shinyApp(ui = ui, server = server)
將height = 300
更改為overflow = "visible"
解決了這個問題!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.