-
-
Save jimbrig/15cffc32b219ce8c154bea9ffb896110 to your computer and use it in GitHub Desktop.
Function to change shiny bootstrap theme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sfThemeSelector = function() { | |
| # -------------------------------------------------------------------------- | |
| # Allow dynamic update of bootstrap theme. | |
| # -------------------------------------------------------------------------- | |
| div( | |
| div( | |
| selectInput( | |
| "shinytheme-selector", "Select 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); | |
| });" | |
| ) | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment