Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何使用DTedit和Shining::uiOutput在列中引入新行?_Html_Shiny_Newline - Fatal编程技术网

Html 如何使用DTedit和Shining::uiOutput在列中引入新行?

Html 如何使用DTedit和Shining::uiOutput在列中引入新行?,html,shiny,newline,Html,Shiny,Newline,我使用DTedit pckg在一个闪亮的应用程序中显示数据框(mydata),因为这个简单的R pckg允许我以非常简单的方式添加/编辑行。到现在为止,一直都还不错。但是,我想在Var2列中引入一个新行(或换行符),将第一行与第二行分开,第三行与第四行分开 我已经能够使用DT::dataTableOutput(下面的选项1)实现这一点。然而,DTedit似乎只适用于shinny::uiOutput,我无法在这里引入新行(选项2)。我读过关于div()的文章,但现在我完全不懂 有人能解释一下我如何

我使用DTedit pckg在一个闪亮的应用程序中显示数据框(mydata),因为这个简单的R pckg允许我以非常简单的方式添加/编辑行。到现在为止,一直都还不错。但是,我想在Var2列中引入一个新行(或换行符),将第一行与第二行分开,第三行与第四行分开

我已经能够使用DT::dataTableOutput(下面的选项1)实现这一点。然而,DTedit似乎只适用于shinny::uiOutput,我无法在这里引入新行(选项2)。我读过关于div()的文章,但现在我完全不懂

有人能解释一下我如何使用Dtedit在数据帧的列中引入新行吗?因此闪亮::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))

选项1:使用DT(DT::dataTableOutput)(工作) ui=fluidPage( h3(“使用DT时新行工作(DT::dataTableOutput)”, 主面板( DT::dataTableOutput(“mytable”) ) ) ) 服务器=功能(输入、输出){ #数据帧
mydata这是通过在
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>');}"))
      )))

}
server=功能(输入、输出){
#数据帧

mydata欢迎使用SO!您是否尝试过在
HTML()中包装例如
mydata$Var2
?顺便说一句,你也可以在你的问题中显示你的图片。谢谢你的建议@BigDataScientist!下次可以。我确实尝试过用html包装它,但它对我不起作用,可能是我做错了。在任何情况下,@Stéphane Laurent提供的以下解决方案都有效,所以这就是我正在实现的。
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>');}"))
      )))

}