我正在尝试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')
))
服务器
library(shiny)
library(shinyjs)
shinyServer(
function(input,output,session) {
observeEvent(input$col, {
js$pageCol(input$col)
})
})
我想这就是你想要的。它编辑h3' element with the
colorLabel`类的innerhtml。我还向ui代码中添加了一个相应的空初始化元素,因此需要进行一些编辑。
library(shiny)
library(shinyjs)
jsCode <- "shinyjs.pageCol = function(params){
$('body').css('background', params);
$('h3.colorLabel').text(params);
};
"
u <- 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'),
tags$h3('',class = 'colorLabel')
))
s <- shinyServer(
function(input,output,session) {
observeEvent(input$col, {
js$pageCol(input$col)
})
})
shinyApp(ui = u,server = s)
产生:
这是内部编辑的内容:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句