我正在尝试selectInput
在tags$h3
. 我想这更像是一个 jquery 问题,但现在它不断添加选定的颜色,而不是“反应地”显示字符串。
我想要的是让里面的字符串h3.colorLabel
被替换。
用户界面
library(shiny)
jsCode <- "shinyjs.pageCol = function(params){
$('body').css('background', params);
/*$('.colorName').after('<h3></h3>').addClass('colorLabel');
$('h3.colorLabel').replaceWith('<h3>'+params+'</h3>').addClass('colorLabel');
*/
$('h3.colorName').after('<h3>'+params+'</h3>').addClass('colorLabel');
};
"
shinyUI( fluidPage(
useShinyjs(),
extendShinyjs(text = jsCode),
selectInput("col", "Colour:",
c("white", "yellow", "red", "blue", "purple")),
tags$h3('Just in case you are color-blind, the background color is:', class='colorName')
))
服务器.R
library(shiny)
library(shinyjs)
shinyServer(
function(input,output,session) {
observeEvent(input$col, {
js$pageCol(input$col)
})
})