r - adding pop up boxes to row names R shiny
问题描述
I am trying to add different messages to different rows in datatable in R shiny. But when I run the below code (this is just an example code, but I want something like that), it only adds the message to one of the row. How can I add to multiple rows?
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)
解决方案
在这里,我修改了你的代码,看看它现在是否适合你:
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))
)
)
)
for (i in 1:3) {
rownames(tdata)[i] <-
as.character(
popify(
actionLink(inputId = paste("t_",i,sep=""), label = rownames(tdata)[i]),
title = paste0("message", i),
placement = "bottom",
trigger = "hover",
options = NULL
)
)
}
datatable(
tdata, container=header, rownames=TRUE, selection='none', escape=FALSE
)
})
}
shinyApp(ui = ui, server = server)
推荐阅读
- logging - .net 核心控制台应用程序日志过滤器通过 appsetting.json
- gitlab - 使用外部 Prometheus 监控 GitLab
- sql - SQL - 哪一列是最大值?
- python-3.x - 如何将 return 语句拆分为多行以实现 flake8 样式
- javascript - 我如何从 JS 的选择选项构建中组合项目的价格
- java - 如何在不阻塞的情况下调用 JmsListener 中的反应式服务?
- android - Api 调用适用于 Volley,但不适用于 Retrofit
- javascript - 我的源代码中的错误(网站连接火力基地)
- javascript - 无法更新父组件
- git - github.com GUI 是否支持将派生存储库同步到基础存储库上的特定提交