사용자가 밝고 어두운 테마를 사용하여 사용자가 UI에서 선택할 수있는 Shiny App을 만들어야합니다. RStudio의 사이트에서 페이지 세부 내용은 themes이고 themeSelector()이지만 "테마 선택기는 응용 프로그램을 개발하는 동안에 만 사용할 수 있습니다." 프로덕션 준비가 된 테마를 동적으로 변경할 수있는 라이브러리가 있습니까?준비 완료 themeSelector for Shiny
1
A
답변
1
개발 중에 만 사용해야 할 수도 있지만 프로덕션 환경에서 사용할 수없는 이유는 없습니다. code을 살펴보면 head
섹션의 stylesheet link
을 찾고 변경하는 것입니다.
javaScript
을 사용하는 것 이외의 다른 방법은 없으므로 이미 작성한 것을 사용하십시오.
당신은 themeSelector
기능이 같은 간단한 selectInput
에 드래그 고정 패널에서 변경 수정할 수 :
library(shiny)
library(shinythemes)
themeSelector <- function() {
div(
div(
selectInput("shinytheme-selector", "Choose a theme",
c("default", shinythemes:::allThemes()),
selectize = FALSE
)
),
tags$script(
"$('#shinytheme-selector')
.on('change', function(el) {
var allThemes = $(this).find('option').map(function() {
if ($(this).val() === 'default')
return 'bootstrap';
else
return $(this).val();
});
// Find the current theme
var curTheme = el.target.value;
if (curTheme === 'default') {
curTheme = 'bootstrap';
curThemePath = 'shared/bootstrap/css/bootstrap.min.css';
} else {
curThemePath = 'shinythemes/css/' + curTheme + '.min.css';
}
// Find the <link> element with that has the bootstrap.css
var $link = $('link').filter(function() {
var theme = $(this).attr('href');
theme = theme.replace(/^.*\\//, '').replace(/(\\.min)?\\.css$/, '');
return $.inArray(theme, allThemes) !== -1;
});
// Set it to the correct path
$link.attr('href', curThemePath);
});"
)
)
}
ui <- fluidPage(
fluidRow(
column(4, themeSelector())
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
+0
코드를 내 애플리케이션에 놓았지만 완벽하게 작동했습니다. 여전히 최종 응용 프로그램에 코드를 통합해야하지만 솔루션이 더 좋을 수는 없습니다. – Frek
당신은 배포 된 응용 프로그램에 themeSelector을 할 수 있습니까? 나는 그것이 테마를 선택하는 데 도움이된다고 생각하지만 dev가 끝났을 때도 앱에 그것을 놓을 수 있습니다. – qfazille
나는 사용자가 어떤 테마를 선택하기를 정말로 원하지 않는다. 사용자가 어둡거나 밝은 테마를 선택할 수있는 옵션을 제공하기 만하면됩니다. 나는 GyD selectInput 컨트롤을 actionButton으로 수정하여 cosmo와 darkly 두 테마 사이에서 선택할 계획입니다. – Frek