Css 将R移动到某个div
与密切相关的是,我正在尝试将Css 将R移动到某个div,css,r,shiny,Css,R,Shiny,与密切相关的是,我正在尝试将showNotification'移动到页面上已经存在的某个div。有没有一个简单的方法 下面的应用程序应该说明这个问题。右下角的通知应显示在黄色分区中 library(shiny) ui=shinyUI(fluidPage( tags$head( tags$style(HTML(" #error {
showNotification
'移动到页面上已经存在的某个div
。有没有一个简单的方法
下面的应用程序应该说明这个问题。右下角的通知应显示在黄色分区中
library(shiny)
ui=shinyUI(fluidPage(
tags$head(
tags$style(HTML("
#error {
width: 100%;
border: black 1px solid;
padding: 5px;
margin: 10px 0;
background-color: #f7f2d9;
}
"))
),
sidebarLayout(
sidebarPanel(
sliderInput("lambda","Number",min = 1,max = 100,value = 27)
),
mainPanel(
h3("Move the slider above 28 to trigger a Notification! "),
plotOutput("algebra"),
div(id = "error", p("The notifications should appear in here")),
tableOutput('table')
)
)
))
server=function(input, output) {
output$algebra <- renderPlot({
if (input$lambda > 28){
showNotification("How can I put this message in the #error div?", id = "error", type = "warning", duration = NULL)
return(NULL)
}
n <- 1:100
lambda <- seq(min(n), max(n), length.out = input$lambda)
plot((2*lambda)+3, type = "o",xlab= "X (number of data points)", ylab = "Y = 2x+3")
})
output$table <- renderTable(iris)
}
shinyApp(ui,server)
库(闪亮)
ui=shinyUI(fluidPage(
标签$head(
标签$style(HTML(“
#错误{
宽度:100%;
边框:黑色1px实心;
填充物:5px;
利润率:10px0;
背景色:#f7f2d9;
}
"))
),
侧边栏布局(
侧栏面板(
滑块输入(“λ”,“数”,最小值=1,最大值=100,值=27)
),
主面板(
h3(“将滑块移动到28上方以触发通知!”),
绘图输出(“代数”),
div(id=“error”,p(“通知应显示在此处”),
tableOutput('table')
)
)
))
服务器=功能(输入、输出){
产出(28美元){
showNotification(“如何将此消息放入#error div?”,id=“error”,type=“warning”,duration=NULL)
返回(空)
}
n这似乎有效:
library(shiny)
library(shinyjs)
ui=shinyUI(fluidPage(
useShinyjs(),
tags$head(
tags$style(HTML("
#error {
width: 100%;
border: black 1px solid;
padding: 5px;
margin: 10px 0;
background-color: #f7f2d9;
}
#shiny-notification-panel {
position: static;
}
"))
),
......
在服务器中
:
output$algebra <- renderPlot({
if(input$lambda > 28){
showNotification("How can I put this message in the #error div?", type = "warning", duration = NULL)
runjs('setTimeout(function(){$("#error").append($("#shiny-notification-panel"))},0);')
return(NULL)
}
......
输出$28){
showNotification(“如何将此消息放入#error div?”,type=“warning”,duration=NULL)
runjs('setTimeout(function(){$(“#error”).append($(“#闪亮的通知面板”)},0);'))
返回(空)
}
......
虽然没有经过高度测试。另一种选择是shinyBS
软件包中的bsAlert
。非常感谢,这很有效。我不确定setTimeout
是否必要?如果没有它,它似乎也可以工作。@SeGa可能没有必要,我还没有测试过。