如何更改全屏中展开按钮(由
full_screen = TRUE
创建)和关闭按钮的文本(我基本上需要翻译成另一种语言)?
MWE:
library(shiny)
library(bslib)
# Define UI
ui <- fluidPage(
theme = bs_theme(bootswatch = "minty"),
titlePanel("Table in a card()"),
mainPanel(
card(
title = "Data Table",
full_screen = TRUE,
tableOutput("mytable")
)
)
)
# Define server logic
server <- function(input, output) {
# Generate sample data
data <- data.frame(
Name = c("John", "Jane", "Alice", "Bob", "Charlie", "David"),
Age = c(25, 30, 35, 40, 45, 50),
Score = c(80, 75, 90, 85, 88, 92)
)
# Render table
output$mytable <- renderTable({
filtered_data <- data
})
}
# Run application
shinyApp(ui = ui, server = server)
下面是使用
JS
的解决方案,我目前看不到直接使用 bslib
内置函数来执行此操作的可能性。但是,请注意,如果您可以选择操作 bslib
函数,那么您也可以尝试此操作,例如'Expand'
被硬编码在 bslib:::full_screen_toggle().
library(shiny)
library(bslib)
# Define UI
ui <- page_fluid(
tags$script(
HTML("$(document).ready(function(){
// The 'Expand' text can be directly manipulated
$('.card.bslib-card > bslib-tooltip > div').text('Erweitern');
// The 'Close' text needs a mutation observer on the card because it
// is only accessible if the full-screen mode is active.
// We replace the html if the card has data-full-screen = true.
var observer = new MutationObserver(function(mutations) {
$('.bslib-full-screen-exit').html($('.bslib-full-screen-exit').html().replace('Close', 'Schließen'))
});
observer.observe(document.getElementsByClassName('card bslib-card')[0], {
attributes: true,
attributeFilter: ['data-full-screen'] });
});")
),
theme = bs_theme(bootswatch = "minty"),
titlePanel("Table in a card()"),
mainPanel(
card(
title = "Data Table",
full_screen = TRUE,
tableOutput("mytable")
)
)
)
# Define server logic
server <- function(input, output) {
# Generate sample data
data <- data.frame(
Name = c("John", "Jane", "Alice", "Bob", "Charlie", "David"),
Age = c(25, 30, 35, 40, 45, 50),
Score = c(80, 75, 90, 85, 88, 92)
)
# Render table
output$mytable <- renderTable({
filtered_data <- data
})
}
# Run application
shinyApp(ui = ui, server = server)