【发布时间】:2018-08-20 23:37:45
【问题描述】:
我正在尝试将不同的消息添加到 R 闪亮数据表中的不同行。但是当我运行下面的代码(这只是一个示例代码,但我想要类似的东西)时,它只会将消息添加到其中一行。如何添加到多行?
library(shiny)
library(shinyBS)
library(DT)
ui <- fluidPage(
titlePanel('All you want to know about Titanic'),
fluidRow(
bsButton('tbutton','Lift Titanic'),
br(),
bsTooltip('tbutton', 'This button will inflate a balloon'),
width=2),
mainPanel(dataTableOutput('titanic')
)
)
server <- function(input, output) {
tdata <- as.data.frame(Titanic)
tdata <- cbind(tdata,tdata)
output$titanic <- DT::renderDataTable({
header <- htmltools::withTags(table(
class = 'display',
thead(
tr(
th(rowspan = 1, 'PassengerID'),
th(colspan = 6, 'Titanic1'),
th(colspan = 6, 'Titanic2')),
tr(lapply(c(" ", rep(colnames(as.data.frame(Titanic)), 2)), th))
)
)
)
rownames(tdata)[1] <-
as.character(popify(actionLink(inputId=paste("t_",i,sep=""),
label=rownames(tdata)[1]), title=paste("message1"), placement =
"bottom", trigger = "hover", options = NULL))
rownames(tdata)[2] <-
as.character(popify(actionLink(inputId=paste("t_",i,sep=""),
label=rownames(tdata)[2]), title=paste("message2"), placement =
"bottom", trigger = "hover", options = NULL))
rownames(tdata)[3] <-
as.character(popify(actionLink(inputId=paste("t_",i,sep=""),
label=rownames(tdata)[3]), title=paste("message3"), placement =
"bottom", trigger = "hover", options = NULL))
datatable(tdata, container=header, rownames=TRUE, selection='none',
escape=FALSE)
})
}
shinyApp(ui = ui, server = server)
【问题讨论】:
-
您的代码中有一个循环,如果您将代码粘贴到 R 中,
i会出现问题