简体   繁体   English

粘贴函数中的R闪亮传递列名称

[英]R shiny passing column name in paste function

I am working on a shiny app, where i need to pass the column names through selectInput. 我正在开发一个闪亮的应用程序,在这里我需要通过selectInput传递列名。 However when i pass the variable name to a paste function it is considering as text instead of a variable/column name. 但是,当我将变量名传递给粘贴函数时,它正在考虑作为文本而不是变量/列名。

lets say i have dataframe ie df3 可以说我有数据框,即df3

df3 <- data.frame(a=c(1:10),b=c(1:10),c=c(1:10),d=c(1:10),e=c(1:10),f=c(1:10),g=c(1:10))

ID  a  b  c  d  e  f  g
1   1  1  1  1  1  1  1
2   2  2  2  2  2  2  2
3   3  3  3  3  3  3  3

using selectInput i will pass the columns e , f, g dynamically based on my requirement 使用selectInput我将根据我的要求动态传递e,f和g列

selectInput("columns1","Select the 1st Filter Variable:", choices = colnames)}})

df3$concate1 <- with(df3, (paste0(a,'+',b,'+',c,'+',input$columns1))

when i pass the variable 'e' the variable name is substituted but not the values in column 'e' ie 当我传递变量“ e”时,将替换变量名,但不替换“ e”列中的值,即

ID concate1
1  1+1+1+e
2  2+2+2+e
3  3+3+3+e

I need to get the values of column 'e' in the df3$concate1 in the below manner. 我需要以以下方式获取df3 $ concate1中列'e'的值。 plz help me in resolving this. 请帮助我解决这个问题。

ID concate1
1  1+1+1+1
2  2+2+2+2
3  3+3+3+3
library(shinydashboard)
library(shiny)

df3 <- data.frame(a=c(1:10),b=c(1:10),c=c(1:10),d=c(1:10),e=c(1:10),f=c(1:10),g=c(1:10))


ui <-  shinyUI(fluidPage(mainPanel(
  selectInput("columns1","Select the 1st Filter Variable:", colnames(df3),colnames(df3[1])),
  textOutput("selection")
)
)
)


server <- function(input, output){  

  output$selection <- renderText({
    column = (input$columns1);
    columnElement = which(colnames(df3) == column)
    df3$concate1 <- with(df3, (paste0(a,'+',b,'+',c,'+',columnElement)))
  })


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM