行动按钮 [英] Issue in action button
本文介绍了行动按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码具有以html呈现的操作按钮.但是,当我单击第二行中的按钮(id为"ang")时,没有显示任何模式框.谁能帮我?不知道为什么这种逻辑无法正常工作.如果我按下普通按钮,则正常工作
The code below has action button in rendered in html. But when i click the button in second row(id as "ang") there is no modal box showing up. Can anyone help me? Not sure why this logic is not working.. If I put a normal button, it is working
library(shiny)
library(shinydashboard)
library(DT)
number_compare <- data.frame(replicate(2, sample(1:100, 10, rep=TRUE)))
# number_compare$direction <- ifelse(
# number_compare$X1 < number_compare$X2,
# as.character(icon("angle-up")),
# as.character(icon("angle-down"))
# )
sidebar <- dashboardSidebar()
body <- dashboardBody(
fluidRow(box(width = 12, solidHeader = TRUE,
DTOutput("example_table"))
)
)
ui <- dashboardPage(dashboardHeader(title = "Example"),
sidebar,
body
)
server <- function(input, output) {
number_compare$X2[which(rownames(number_compare) == 2)] = paste(with(number_compare, X2[rownames(number_compare) == 2])," ", as.character(actionButton("ang","")))
number_compare$X2[which(rownames(number_compare) == 4)] = paste(with(number_compare, X2[rownames(number_compare) == 4])," ", as.character(actionButton("angle2","", icon("angle-up"),style = "border: none;
outline:none;background:white")))
number_compare$X2[which(rownames(number_compare) == 6)] = paste(with(number_compare, X2[rownames(number_compare) == 6])," ", as.character(actionButton("angle3","", icon("angle-up"),style = "border: none;
outline:none;background:white")))
output$example_table <- DT::renderDT({
datatable(
number_compare,
escape = FALSE)
})
observeEvent(input$ang,{
showModal(modalDialog(
title = "Somewhat important message",
"This is a somewhat important message.",
easyClose = TRUE,
footer = NULL
))
})
}
shinyApp(ui, server)
我得到了下面的代码的解决方案.我做了一个小小的改变.如果我更改输入日期并单击箭头,则不会弹出.不确定我犯了什么错误(Basicall,如果我两次单击"sam"按钮,则单击箭头时并不会弹出模式框
I got the solution with below code . Just a small change I did. If i change the input date and click on arrow, it not popping up. Not sure what mistake I am making (Basicall, if I click "sam" button twice, the arrow is not popping up modal box when it is clicked
library(shiny)
library(shinydashboard)
library(DT)
number_compare <- data.frame(replicate(2, sample(1:100, 10, rep=TRUE)))
# number_compare$direction <- ifelse(
# number_compare$X1 < number_compare$X2,
# as.character(icon("angle-up")),
# as.character(icon("angle-down"))
# )
sidebar <- dashboardSidebar()
body <- dashboardBody(
fluidRow(box(width = 12, solidHeader = TRUE,
DTOutput("example_table"),
actionButton("sam","sam"),
dateInput("da","Date", value = Sys.Date(), min = Sys.Date()-1, max = Sys.Date()+1))
)
)
ui <- dashboardPage(dashboardHeader(title = "Example"),
sidebar,
body
)
server <- function(input, output) {
number_compare$X2 <- paste("sd",number_compare$X2)
number_compare$X2[which(rownames(number_compare) == 2)] = paste(with(number_compare, X2[rownames(number_compare) == 2])," ", " ",as.character(actionLink(inputId="ang", label="", icon("caret-up"))))
print(paste(with(number_compare, X2[rownames(number_compare) == 2])," ", as.character(actionButton("ang",""))))
# number_compare$X2[which(rownames(number_compare) == 4)] = paste(with(number_compare, X2[rownames(number_compare) == 4])," ", as.character(actionButton("angle2","", icon("angle-up"),style = "border: none;
# outline:none;background:white")))
observeEvent(input$sam,{
if(input$da == Sys.Date()){
output$example_table <- DT::renderDT({
datatable(
number_compare[c(2,3:4),],
escape = FALSE
,options=list(preDrawCallback=JS(
'function() {
Shiny.unbindAll(this.api().table().node());}'),
drawCallback= JS(
'function(settings) {
Shiny.bindAll(this.api().table().node());}')))
})
}
else {
output$example_table <- DT::renderDT({
datatable(
number_compare[c(2,5:10),],
escape = FALSE
,options=list(preDrawCallback=JS(
'function() {
Shiny.unbindAll(this.api().table().node());}'),
drawCallback= JS(
'function(settings) {
Shiny.bindAll(this.api().table().node());}')))
})
}
})
# tolisten <- reactive({
# list(input$ang, input$da)
# })
observeEvent(input$ang,{
if(!is.null(input$da))
{
print("clicked")
showModal(modalDialog(
title = "dsd"
))
}
})
}
shinyApp(ui, server)
推荐答案
您必须绑定:
output$example_table <- DT::renderDT({
datatable(
number_compare,
escape = FALSE,
options = list(
preDrawCallback = JS('function() { Shiny.unbindAll(this.api().table().node()); }'),
drawCallback = JS('function() { Shiny.bindAll(this.api().table().node()); } ')
)
)
})
这篇关于行动按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文