- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 DTedit pckg 在 Shiny 的应用程序中显示数据框 (mydata),因为这个简单的 R pckg 允许我以非常简单的方式添加/编辑行。到目前为止,一切都很好。但是,我想在 Var2 列中引入一个新行(或换行符),将第一行与第二行分开,将第三行与第四行分开。
我已经能够使用 DT::dataTableOutput(下面的选项 1)做到这一点。但是,DTedit 似乎只能与 shiny::uiOutput 一起使用,而且我无法在那里引入新行(选项 2)。我读过有关 div() 的内容,但我现在完全一无所知。
有人可以阐明我如何使用 Dtedit 在数据框的列中引入新行吗?因此 shiny::uiOutput?
注意:我得出的结论是 shiny::uiOutput 是这里的问题,因为这是我在这两个选项之间看到的唯一“明显”区别。但这只是我,我可能缺少一些不那么明显的东西。
PD:这是我的第一篇文章,所以请告诉我是否可以做得更好。谢谢!
# OPTION 1: using DT (DT::dataTableOutput) (WORKING)
ui = fluidPage(
h3("New line works when using DT (DT::dataTableOutput)",
mainPanel(
DT::dataTableOutput("mytable")
)
)
)
server = function(input, output){
#dataframe
mydata <- data.frame(Var1 = c("a", "b"),
Var2 = c("FIRST LINE: first; SECOND LINE: second",
"THIRD LINE: third; FOUR LINE: four"))
#Subtitute semicolon by break line based on
#https://stackoverflow.com/questions/26368192/how-to-insert-new-line-in-r-shiny-string
mydata$Var2 <- gsub(pattern = "; ", replacement = "<br/>", mydata$Var2)
#render table
output$mytable = DT::renderDataTable(escape = F,
mydata
)
}
shinyApp(ui = ui, server = server, options = list(height = 1080))
# OPTION 2: using DTedit, therefore shiny::uiOutput, (not working)
ui = fluidPage(
h3("New line does not work when using DTedit-shiny::uiOutput"),
mainPanel(
shiny::uiOutput("mytable")
)
)
server = function(input, output){
#dataframe
mydata <- data.frame(Var1 = c("a", "b"),
Var2 = c("FIRST LINE: first; SECOND LINE: second",
"THIRD LINE: third; FOUR LINE: four"))
#Subtitute semicolon by break line based on
#https://stackoverflow.com/questions/26368192/how-to-insert-new-line-in-r-shiny-string
mydata$Var2 <- gsub(pattern = "; ", replacement = "<br/>", mydata$Var2)
#render table
output$mytable = DT::renderDataTable(escape = F,
DTedit::dtedit(input, output,
name = 'mytable',
thedata = mydata)
)
}
shinyApp(ui = ui, server = server, options = list(height = 1080))
想要的结果:
到目前为止的实际结果:
最佳答案
这通过在 render
函数中用 JavaScript 进行替换来实现:
server = function(input, output){
#dataframe
mydata <- data.frame(Var1 = c("a", "b"),
Var2 = c("FIRST LINE: first; SECOND LINE: second",
"THIRD LINE: third; FOUR LINE: four"))
#render table
DTedit::dtedit(
input, output,
name = 'mytable',
thedata = mydata,
datatable.options = list(
columnDefs = list(
list(targets=1,
render = JS("function(data){return data.replace(/;/g, '<br>');}"))
)))
}
关于html - 如何使用 DTedit 和 shiny::uiOutput 在列中引入新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56590555/
我在设计嵌套输入/输出应用时遇到了问题。 (我也试过把这个问题发到shiny-discuss,但是发的时候会被自动删除,为什么?) 我的应用程序可以简化为以下步骤: 按文本区域输入数据集。即:inpu
我在 server.R 中设置了 UI 以获得更多控制,但在 server.R 中定义时,shinyDashboard 不起作用。 我将此方法与 navBarPage 一起使用没有问题。 此代码有效
在我的应用程序中,我有一个模块嵌套在另一个模块中。父模块和子模块都使用 renderUI( slider )创建 UI 输出,并根据此 slider 的值过滤显示在 ggplot 上的数据。我在常规的
我正在尝试根据用户的 selectInputs 生成一个序列。现在的问题是序列的布局是垂直的。我的问题是如何水平或内联对齐它们。我尝试将 uiOutput 设置为 inline=TRUE,但它没有按预
uiOutput('myTable')其次是 p("Here is some text....")将文本放在 uioutput 旁边显示,但我喜欢从页面左侧开始在新行中打印文本。添加br()只是添加相
我正在尝试添加和删除 uiOutput元素使用索引来跟踪每个单独的元素。有一个actionButton用于向列表中添加和元素,以及 x 删除所选项目的每个元素的按钮,如下图所示: 我正在使用一个包含
每次我使用 renderUI(服务器端)和 uiOutput(UI 端)时,html 都是由 div 包装的,我怎样才能用 span 包装它呢? 例如: 用户界面方面: tags$p(uiOutput
@lz100 帮助我自动缩放 uiOutput()当我切换到显示/隐藏侧面板时。但是,当我实现 esquisserUI() ,当您在侧面板中的单选按钮之间来回切换时,与之关联的小部件会移位。 另一个问
我有一个非常基本的 Shiny 应用程序。 我正在使用 renderUI 和 uiOutput 来填充可以选择日期的 selectInput。 但如果用户通过单选按钮选择一个选项,我只希望 selec
我喜欢在 Shiny 的应用程序中单击键盘上的 Enter 键时触发操作按钮。当我将 actionButton 放入 ui 中时它可以工作,但与 uiOutput 一起使用时它不起作用。 librar
我正在使用 DTedit pckg 在 Shiny 的应用程序中显示数据框 (mydata),因为这个简单的 R pckg 允许我以非常简单的方式添加/编辑行。到目前为止,一切都很好。但是,我想在 V
我下面有 R Shiny 应用程序,我可以在浏览器中显示 uiOutput,现在我想添加 downloadHandler 以将 uiOutput 的内容下载到 HTML 文档。 下面是我的代码 lib
我正在尝试使用通过 Shiny 的下拉菜单插入和退出的 slider 制作一个响应式(Reactive) UI。我有一个带有响应式 UI slider 的服务器(server.R): library(
在 ui.R , 我放: uiOutput("singlefactor") 在 server.R , 我有: output$singlefactor <- renderUI({ selec
我正在尝试显示从 1 到 5 tabPanels在navbarPage在 Shiny 。 我的代码生成了 5 个图,但我希望用户能够选择他们想要访问的数量——在每个 tabPanel 中显示一个图。
我正在尝试将我的 shinydashboards 移植到 flexdashboard,但我遇到了在服务器端呈现的对象的问题。 在这个例子中,我有一个在服务器端呈现的输入选择器 output$weekl
我是一名优秀的程序员,十分优秀!