0
votes

I want to create a reactive data frame with a reactive column name in shiny. However this is throwing error. I have provided the code below.. The error is being caused by an () followed by =, but I cant find a way around. Any help will be appreciated

ui.R

library(shiny)
shinyUI(fluidPage(
  titlePanel("Tool"),
  sidebarLayout(
    sidebarPanel(
      textInput("Item","Enter Item Name"),
      div(class='row-fluid',
          div(class='span6', numericInput("sales1","Enter Sales",value=0),numericInput("sales2","Enter Sales",value=0)),
          div(class='span6', numericInput("prices1","Enter price",value=0),numericInput("prices2","Enter price",value=0))
      )),
    mainPanel(
      dataTableOutput("table")
      )
  )
  ))

server.R

library(shiny)
shinyServer(function(input, output) {
  prices<-reactive({
    c(input$prices1,input$prices2)
  })
  sales<-reactive({
    c(input$sales1,input$sales2)
  })
  combined<-reactive({
    data.frame(prices(),sales())
  })
  combined_final<-reactive({
    mutate(combined(),Rev=prices()*sales())
  })
  namerev<-reactive({
    as.character(paste("Rev",input$Item,sep="_"))
  })
  combined_final_rename<-reactive({
    rename_(combined_final(),namerev() ="Rev")
  })
  output$table<-renderDataTable({
    combined_final_rename()
  })
  })
1
Just out of curiosity -- why do you need so many reactive expressions? In your example, one combined reactive() would be just fine...Marat Talipov
Actually this a part of a larger code. I had to create a small example. And you are perfectly right in pointing that there are too many reactive expressions. It was a hasty work.Rajarshi Bhadra

1 Answers

2
votes

If I understood the question correctly, you might need something like that:

  combined_final_rename<-reactive({
    d <- combined_final()
    colnames(d)[colnames(d)=='Rev'] <- namerev()
    d
  })