R 闪亮书签按钮
R shiny bookmark button
我尝试更改书签按钮弹出窗口中的文本(其他语言),但我不知道该怎么做?有没有人知道:
library(shiny)
enableBookmarking(store = "url")
ui <- fluidPage(
selectInput("test", label = "option", choices = c("opt A", "opt B"))
, bookmarkButton(label = "")
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
Change the text in the red rounds
正如@Tschösi 所说,这些值是硬编码在函数中的,因此您有两个选择:
- 您创建自己的函数副本,替换硬编码版本。
- 您应用一些 Javascript 来动态更改文本。
就我个人而言,我更喜欢选项 2。
这是一个如何做到这一点的工作示例:
library(shiny)
js <- HTML(paste("$(function() {",
"$('body').on('shown.bs.modal', function() {",
"$('.modal-dialog .modal-header > .modal-title').text('Speicher Lesezeichen')",
"$('.modal-dialog .modal-body > span:first').text('Dieser Link speichert den aktuellen Status der Applikation.')",
"$('#shiny-bookmark-copy-text').text('Drücken Sie Ctrl-C um den Link zu kopieren.')",
"$('.modal-dialog .modal-footer > button').text('Schließen')",
"})",
"})",
sep = "\n"))
ui <- function(request) {
fluidPage(
tags$head(tags$script(js, type = "text/javascript")),
tabsetPanel(id = "tabs",
tabPanel("One",
checkboxInput("chk1", "Checkbox 1"),
bookmarkButton(id = "bookmark1")
),
tabPanel("Two",
checkboxInput("chk2", "Checkbox 2"),
bookmarkButton(id = "bookmark2")
)
)
)
}
server <- function(input, output, session) {
# Need to exclude the buttons from themselves being bookmarked
setBookmarkExclude(c("bookmark1", "bookmark2"))
# Trigger bookmarking with either button
observeEvent(input$bookmark1, {
session$doBookmark()
})
observeEvent(input$bookmark2, {
session$doBookmark()
})
}
enableBookmarking(store = "url")
shinyApp(ui, server)
使用thothal的建议,问题已解决:
library(shiny)
enableBookmarking(store = "url")
ui <- fluidPage(
useShinyjs()
, tags$head(
tags$script(src = "bookmark_vertaling.js")
)
, selectInput("test", label = "option", choices = c("opt A", "opt B"))
, bookmarkButton(label = "", onclick = JS("bookmark_vertaling()"))
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
在 www 目录中使用这个名为“bookmark_vertaling.js”的 js 脚本:
function bookmark_vertaling() {
$('body').on('shown.bs.modal', function() {
$('.modal-dialog .modal-title').text('Rechtstreekse link naar deze pagina.');
$('.modal-dialog .modal-body > span:first').empty();
$('#shiny-bookmark-copy-text').text('Kopieer deze link (ctrl-c) om rechtstreeks naar deze pagina te linken.');
$('.modal-dialog .modal-footer > button').text('Sluiten');
});
}
此 js 脚本使用 tags$script 加载到仪表板中(确保您在 www 目录中有此脚本以使其在浏览器中可用)。当我点击 bookmarkButton (onclick)
时调用这个 js 函数
我尝试更改书签按钮弹出窗口中的文本(其他语言),但我不知道该怎么做?有没有人知道:
library(shiny)
enableBookmarking(store = "url")
ui <- fluidPage(
selectInput("test", label = "option", choices = c("opt A", "opt B"))
, bookmarkButton(label = "")
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
Change the text in the red rounds
正如@Tschösi 所说,这些值是硬编码在函数中的,因此您有两个选择:
- 您创建自己的函数副本,替换硬编码版本。
- 您应用一些 Javascript 来动态更改文本。
就我个人而言,我更喜欢选项 2。
这是一个如何做到这一点的工作示例:
library(shiny)
js <- HTML(paste("$(function() {",
"$('body').on('shown.bs.modal', function() {",
"$('.modal-dialog .modal-header > .modal-title').text('Speicher Lesezeichen')",
"$('.modal-dialog .modal-body > span:first').text('Dieser Link speichert den aktuellen Status der Applikation.')",
"$('#shiny-bookmark-copy-text').text('Drücken Sie Ctrl-C um den Link zu kopieren.')",
"$('.modal-dialog .modal-footer > button').text('Schließen')",
"})",
"})",
sep = "\n"))
ui <- function(request) {
fluidPage(
tags$head(tags$script(js, type = "text/javascript")),
tabsetPanel(id = "tabs",
tabPanel("One",
checkboxInput("chk1", "Checkbox 1"),
bookmarkButton(id = "bookmark1")
),
tabPanel("Two",
checkboxInput("chk2", "Checkbox 2"),
bookmarkButton(id = "bookmark2")
)
)
)
}
server <- function(input, output, session) {
# Need to exclude the buttons from themselves being bookmarked
setBookmarkExclude(c("bookmark1", "bookmark2"))
# Trigger bookmarking with either button
observeEvent(input$bookmark1, {
session$doBookmark()
})
observeEvent(input$bookmark2, {
session$doBookmark()
})
}
enableBookmarking(store = "url")
shinyApp(ui, server)
使用thothal的建议,问题已解决:
library(shiny)
enableBookmarking(store = "url")
ui <- fluidPage(
useShinyjs()
, tags$head(
tags$script(src = "bookmark_vertaling.js")
)
, selectInput("test", label = "option", choices = c("opt A", "opt B"))
, bookmarkButton(label = "", onclick = JS("bookmark_vertaling()"))
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
在 www 目录中使用这个名为“bookmark_vertaling.js”的 js 脚本:
function bookmark_vertaling() {
$('body').on('shown.bs.modal', function() {
$('.modal-dialog .modal-title').text('Rechtstreekse link naar deze pagina.');
$('.modal-dialog .modal-body > span:first').empty();
$('#shiny-bookmark-copy-text').text('Kopieer deze link (ctrl-c) om rechtstreeks naar deze pagina te linken.');
$('.modal-dialog .modal-footer > button').text('Sluiten');
});
}
此 js 脚本使用 tags$script 加载到仪表板中(确保您在 www 目录中有此脚本以使其在浏览器中可用)。当我点击 bookmarkButton (onclick)
时调用这个 js 函数