我们如何在 shinyapp 中复制具有不同属性名称的现有属性值?

How do we duplicate existed attribute values with different attribute name in shinyapp?

如果有人能帮助满足以下要求,那就太好了。

    url <-  "https://bbolker.github.io/mpha_2019/gapminder_index.csv"
dt <-   fread(url)

# UI
ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
                textInput("newcolumnname", "Custom Attribute Name"),
                selectInput("formula", "Enter Custom Formula", choices = unique(names(dt)), multiple = TRUE),
                actionButton("addnewcolumn", "Add new column")
                ),
    mainPanel(
      DT::DTOutput("data_tbl")
    )
  )
)
#SERVER
server <- function(input, output, session) {
  reactive_dt <- eventReactive(input$addnewcolumn, {
    if (input$newcolumnname != "" &&
        !is.null(input$newcolumnname) && input$addnewcolumn > 0) {
      #newcolval <- dt$input$formula
      newcolval <- dt[,input$formula]
      newcol <- data.table(newcolval)
      names(newcol) <- input$newcolumnname
      dt <<- cbind(dt, newcol)
    }
    dt
  })
  
  output$data_tbl <- DT::renderDT({ head(reactive_dt(),5) })
  }
#Run the Shiny App to Display Webpage
shinyApp(ui = ui, server = server) 

需求详情:-

想在名为“Category_provider”的新列下连接“Category/Provider”属性值的值,不幸的是,它在 UI [=22] 中显示属性名称而不是值=].为达到要求,我的代码中的更正是什么。

试试这个,

url <-  "https://bbolker.github.io/mpha_2019/gapminder_index.csv"
dt <-   as.data.frame(fread(url))

# UI
ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
                textInput("newcolumnname", "Custom Attribute Name"),
                selectInput("formula", "Enter Custom Formula", choices = unique(names(dt)), multiple = TRUE),
                actionButton("addnewcolumn", "Add new column")
            
                ),
    mainPanel(
      DT::DTOutput("data_tbl")

    )
  )
)
#SERVER
server <- function(input, output, session) {
  reactive_dt <- eventReactive(input$addnewcolumn, {
    if (input$newcolumnname != "" &&
        !is.null(input$newcolumnname) && input$addnewcolumn > 0) {

        newcol <- apply(dt[,input$formula] , 1, function(x) paste(x, collapse = "_"))

        cn <-colnames(dt)
        dt <<- data.frame(dt, newcol)
        colnames(dt) <- c(cn,input$newcolumnname)
    }
    dt
  })
  
  output$data_tbl <- DT::renderDT({ head(reactive_dt(),5) })
  }
#Run the Shiny App to Display Webpage


shinyApp(ui = ui, server = server)