标签: dt

运行 R闪亮应用程序时如何编辑数据表函数中的列名称?

我正在使用 R Shiny 中 DT 包中的数据表函数,我希望我的应用程序的用户可以编辑列名称(变量名称)。有什么选择可以做到这一点吗?

现在我使用文本输入“old_var_name”、文本输入“new_var_name”和操作按钮“update_variable_name”。但此时,我只能更改变量名称。我希望用户能够更改他想要的变量名称。

服务器:

tab <- eventReactive(input$import,{
inFile <- input$file1
if (is.null(inFile))
  return(NULL)

tabledata <- read.xlsx(inFile$datapath,startRow=1,sheet = 1)
})

name_temp <- eventReactive(input$var_name,{
if (input$old_name == ""){
  colnames(tab())
} else {
    c(colnames(tab())[1:(which(colnames(tab()) == input$old_name)-1)],input$new_name,
    colnames(tab())[(which(colnames(tab()) == input$old_name)+1):length(colnames(tab()))])
}
})

final_rename <- reactive({
d <- tab()
colnames(d) <- name_temp()
d
})

output$tabledata <- DT::renderDataTable({
if (input$var_name == 0) {
  DT::datatable(tab(),editable = T)
} else {
  DT::datatable(final_rename(),editable = T)
}
})
Run Code Online (Sandbox Code Playgroud)

用户界面:

tabPanel("Table",h1("Table",align="center") ,
actionButton(inputId = "import", label = …
Run Code Online (Sandbox Code Playgroud)

r datatables shiny dt

1
推荐指数
1
解决办法
1603
查看次数

R闪亮应用程序-编辑DT中的值并更新

我有一个闪亮的应用程序,其中一项功能是允许用户编辑表中的值,当单击运行时,它将使用用户输入作为函数的值,然后更新同一个表中的结果。下面是当前表和预期表的示例。因此,在第一个表中,如果用户更改通道 A 和 C 的电流值并单击运行,它应该将自身更新为表预期输出中反映的值。

所以我的问题是,是否可以将可编辑的 DT 值作为函数的输入。

library(shiny)
library(DT)
shinyApp(
  ui = fluidPage(
    DT::dataTableOutput("x1"),
    actionButton("opt_run", "Run"),
    tags$h1("Expected Output"),
    DT::dataTableOutput("x2")
  ),
  server = function(input, output, session) {

    df <- data.table(Channel = c("A", "B","C"),
                     Current = c("2000", "3000","4000"),
                     Modified = c("2500", "3500","3000"),
                     New_Membership = c("450", "650","700"))

    output$x1 = renderDT(df, selection = 'none', editable = TRUE)

    expdf <- data.table(Channel = c("A", "B","C"),
                     Current = c("3000", "3000","5000"),
                     Modified = c("3500", "3500","6000"),
                     New_Membership = c("650", "650","1100"))

    output$x2 = renderDT(expdf, selection = 'none', …
Run Code Online (Sandbox Code Playgroud)

r shiny dt

1
推荐指数
1
解决办法
2577
查看次数

需要在数据表的一行中应用条件格式

我正在尝试使用 styleInterval (在 DT 包的 formatStyle 内)将条件格式应用于数据表的一行。我在网上找到的所有示例要么用于格式化整个数据表,限制涉及的列,要么根据单列中的值格式化整个行。

我想将涉及的行限制为以下示例中的第一行(“entity1”)。

entity <- c('entity1', 'entity2', 'entity3')
value1 <- c(21000, 23400, 26800)
value2 <- c(21234, 23445, 26834)
value3 <- c(21123, 234789, 26811)
value4 <- c(27000, 23400, 26811)
entity.data <- data.frame(entity, value1, value2, value3, value4)

DT::datatable(entity.data) %>%
  formatStyle(columns = 2:5,
              backgroundColor = styleInterval(cuts = c(21200,22000),
                                              values = c('red','white','green')))
Run Code Online (Sandbox Code Playgroud)

我是否缺少使用 formatStyle 执行此操作的方法,或者我是否需要使用另一个函数/包来解决此问题?谢谢!

r dt

1
推荐指数
1
解决办法
653
查看次数

如何在闪亮的可编辑数据表中指定文件名并限制列编辑

我这里有一个闪亮的应用程序示例。它使用包显示可编辑的DT数据表。

为了能够下载多个页面上显示的所有数据,我server=FALSE与 一起使用renderDT

我现在想要实现的是

  1. 限制用户编辑某些特定列。下面的代码似乎不起作用。

    editable = list(target = 'cell', disable = list(column = c("Sepal.Length", "Sepal.Width")))

  2. 我想在导出到 csv 时指定默认文件名,例如 data.csv. 那可能吗?

如果有人能帮助我,我将非常感激。多谢。

    library(shiny)
    library(DT)
    library(dplyr)    
    # UI
    ui = fluidPage(
        selectInput("nrows",
                    "select n entries",
                    choices = 100:150,
                    selected = 100,
                    multiple = FALSE),
        DT::dataTableOutput('tbl'),
                   checkboxGroupInput('datacols', 
                                      label='Select Columns:',
                                      choices= c('Sepal.Length', 'Sepal.Width', 'Petal.Length', 'Petal.Width', 'Specie'),
                                      selected = c('Sepal.Length', 'Sepal.Width', 'Petal.Length', 'Petal.Width', 'Specie'),
                                      inline=TRUE )

    )

    # SERVER
    server = function(input, output) {



        df = …
Run Code Online (Sandbox Code Playgroud)

r shiny dt

1
推荐指数
1
解决办法
2021
查看次数

向Shiny DT添加按钮以拉出模态框

我正在尝试在数据表中添加一列按钮,单击这些按钮将弹出一个模式,但我在使用我在此处此处在网上找到的示例时遇到了问题。

我的一些要求:

  • 需要处理数据集中未知数量的行(可能是 5、可能是 10、可能是 500)
  • 每个按钮都需要是唯一的 id,我可以用它来引用行(在示例中,您可以看到我将行号拉入模态 - 现实生活中,我使用行号来子集我的数据,并实际将信息放入模态)

代码:

library(shiny)
library(shinydashboard)
library(DT)

ui = dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    DTOutput('x1'),
    verbatimTextOutput("test")
    )
    )

server = function(input, output) {

  ##DATA TABLE WHERE I NEED A BUTTON##

  output$x1 = renderDT(
    iris,
    selection = 'single',
    options = list(
    )
  )

  ##MODAL CALLED BASED ON BUTTON CLICK

  observeEvent(input$x1_cell_clicked, {

    row = input$x1_cell_clicked$row

    if (is.null(row) || row == '') {} else{

      showModal(modalDialog(
        title = paste0("Timeline!",row),
        size = "s",
        easyClose = …
Run Code Online (Sandbox Code Playgroud)

r shiny dt

1
推荐指数
1
解决办法
2058
查看次数

在R闪亮中,如何将滚动合并到模式对话框中?

在运行下面的 MWE 代码时,如底部图像所示,用户输入到模态对话框中呈现的矩阵中会导致矩阵压缩。用户输入到矩阵中的列越多,矩阵压缩得越多,直到留下一个难以阅读的矩阵。

有没有办法在添加列时不允许矩阵压缩,而是向右扩展,用户使用滚动条向左/向右导航?今天早上我一直在尝试插入滚动条,但还没有成功。

也许挑战在于shinyMatrix包装本身。我想知道是否可以使用 DT Table,因为它呈现得很好(带有滚动),并shinyMatrix作为输入/输出的后端引擎?Packagerhandsontable虽然很漂亮,但在模式对话框中效果不佳。

MWE代码:

library(shiny)
library(shinyMatrix)

ui <- fluidPage(

  sidebarLayout(
    sidebarPanel(
      uiOutput("panel"),
      actionButton("show2nd","Show 2nd input (in modal)")
    ),
    mainPanel(plotOutput("plot1"))
  )
)

server <- function(input, output, session){
 
  output$panel <- renderUI({
    tagList(
      matrixInput("input1", 
        value = matrix(c(10,5), 1, 2, dimnames = list(c("1st input"),c("X|Y",""))),
        rows =  list(extend = FALSE, names = TRUE),
        cols =  list(extend = FALSE, 
                     delta = 1,
                     delete = FALSE,
                     names = TRUE, 
                     editableNames = FALSE,
                     multiheader=TRUE),
        class = "numeric"),
      helpText("Generate …
Run Code Online (Sandbox Code Playgroud)

r modal-dialog shiny dt

1
推荐指数
1
解决办法
745
查看次数

如何在闪亮模块的数据表中添加复选框?

我有一个闪亮的模块,它显示一个带有评论列的表格,用户可以在客户端输入文本,然后评论将存储在数据库中。现在,我想添加另一列带有复选框并将其相应的值(TRUE/FALSE)存储在数据库中。不确定如何从表中检索复选框值。以下是我对示例数据的尝试。

library(tidyverse)
library(shinyWidgets)
library(shiny)
library(htmlwidgets)


mtcars_df <- mtcars %>% 
  rownames_to_column(var="car")


writeback_UI <- function (id) {
  ns <- NS(id)

  DT::dataTableOutput(ns('records_tbl'))
  
}
shinyInput = function(FUN, len, id, ...) {
  inputs = character(len)
  for (i in seq_len(len)) {
    inputs[i] = as.character(FUN(paste0(id, i), label = NULL, ...))
  }
  inputs
}

# obtain the values of inputs
shinyValue = function(id, len) {
  unlist(lapply(seq_len(len), function(i) {
    value = input[[paste0(id, i)]]
    if (is.null(value)) NA else value
  }))
}




writeback_server <- function (id,records_data) {
  #stopifnot(is.reactive(records_data))
  shiny::moduleServer(id, function (input,output,session) …
Run Code Online (Sandbox Code Playgroud)

checkbox r shiny dt shinymodules

1
推荐指数
1
解决办法
2553
查看次数

闪亮的 R 中的水平滚动问题

我在新的闪亮 R 中,但水平滚动有问题。这是我的代码。

output$sbirx.view <- DT::renderDataTable(
{
  dataset.filter()
}, options = list(
                  searching = TRUE,
                  autoWidth=TRUE,
                  paging=FALSE,
                  scrollX=TRUE,
                  scrollY="500px",
                  scrollCollapse = TRUE,
                  fixedHeader=TRUE,
                  fixedColumns=list(leftColumns = 2, rightColumns = 0, 
                                    heightMatch = 'none')
                ),
            rownames=FALSE,
            class = 'cell-border stripe',
            extensions = c('FixedColumns',"FixedHeader")
Run Code Online (Sandbox Code Playgroud)

)

数据有 79 列,我可以选择要显示的列数。前 2 个 leftcolumns(DISEASE 和 PRODUCT)应该是固定的,如果你只显示 3 列,表格看起来像这样。但是,如果我选择适合屏幕的几列,则没有问题。

疾病产品 疾病产品 2010-11 疾病1 产品1 疾病1 产品1 25,000 疾病1 产品2 疾病1 产品2 15,000 疾病1 产品3 疾病1 产品3 5,000

有没有办法使用任何选项来解决这个问题?

感谢您的时间和帮助。

scroll r horizontal-scrolling shiny dt

0
推荐指数
1
解决办法
3450
查看次数

如何在R Shiny数据表中添加自定义按钮?

有一个选项可以在datatables.net网站上添加自定义按钮。如何在R Shiny应用中进行编码?一个按钮和观察者的基本R代码示例将非常有趣。

这是来自https://datatables.net/extensions/buttons/examples/initialisation/custom.html的 JS代码

$(document).ready(function() {
    $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            {
                text: 'My button',
                action: function ( e, dt, node, config ) {
                    alert( 'Button activated' );
                }
            }
        ]
    } );
} );
Run Code Online (Sandbox Code Playgroud)

谢谢 !

user-interface r button shiny dt

0
推荐指数
1
解决办法
1137
查看次数

单击闪亮数据表中的按钮后如何滚动到底部

我有一个简单的闪亮应用程序,它以闪亮的方式向我显示数据表中的大量图片。我有 20,000 张图像,我想删除那些我不喜欢的图像。当我删除一行时,应用程序会将我带到数据表的顶部,这对于这么多图像没有用处。

作为一种简单的解决方案,我认为我可以确保应用程序返回到我刚刚删除的图像上方。我想这将由 javascript 函数管理,但我不知道如何实现它。我想它应该放在下面的代码部分中tags$script。有人可以告诉我如何/指导我如何实现此功能

这是我的应用程序的代码:

服务器

library(shiny)
library(shinydashboard)
library(data.table)
library(DT)
server<-shinyServer(function(input, output) {
  vals<-reactiveValues(myTabData = data.table(NULL))

  vals$Data<-data.table(Endo_Endoscopist=DT$Endo_Endoscopist,
                        PatientID=DT$PatientID,
                        NBIorWLorFICE=DT$NBIorWLorFICE,
                        url=DT$url)

  output$MainBody<-renderUI({
    fluidPage(
      box(width=12,
          h3(strong("Actions on datatable with buttons"),align="center"),
          hr(),
          column(12,dataTableOutput("Main_table")),
          tags$script("$(document).on('click', '#Main_table button', function () {
                      Shiny.onInputChange('lastClickId',this.id);
                      Shiny.onInputChange('lastClick', Math.random())
  });")

      )
      )
  })

  output$Main_table<-renderDataTable({
    DT=vals$Data

    DT[["Actions"]]<-
      paste0('
             <div class="btn-group" role="group" aria-label="Basic example">
             <button type="button" class="btn btn-secondary delete" id=delete_',1:nrow(vals$Data),'>Delete</button>
             <button type="button" class="btn btn-secondary modify"id=modify_',1:nrow(vals$Data),'>Modify</button>
             </div>

             ')
    datatable(DT,
              escape=F)}
      )


  output$downloadData <- downloadHandler(
    filename = function() {
      "Main_table.csv" …
Run Code Online (Sandbox Code Playgroud)

javascript r datatables shiny dt

0
推荐指数
1
解决办法
755
查看次数

生成一个包含两个列表之间所有可能组合的数据框

你好,我有两个清单:

list1<-c("A","B")
list2<-c(1,2,3)
Run Code Online (Sandbox Code Playgroud)

我想获得所有可能的组合并将其保存到数据框中,例如:

带有一个名为的列Possibilities,它指的是可能性的名称。

list1 list2 Possibilities
A     1     P1
B     1     P1
A     2     P2
B     2     P2
A     3     P3
B     3     P3
A     1     P4
B     2     P4
A     2     P5
B     1     P5
A     3     P6
B     1     P6
A     1     P7
B     3     P7
A     2     P8
B     3     P8
A     3     P9
B     2     P9
Run Code Online (Sandbox Code Playgroud)

解决方案 :

> expand.grid(list1,list2)
Run Code Online (Sandbox Code Playgroud)

不是我想要的,因为它给出了:

  Var1 Var2
1    A    1
2    B    1
3    A    2 …
Run Code Online (Sandbox Code Playgroud)

combinations r dplyr dt

-3
推荐指数
1
解决办法
74
查看次数