how to take column names as varible from input from a slide panel "select Input" widget and use them

1,864 views
Skip to first unread message

Apoorv Mehta

unread,
Apr 2, 2014, 4:44:55 AM4/2/14
to shiny-...@googlegroups.com

Hi all, I am sorry I am new here and tried to go through existing questions but could not get the answer to my question.

I am trying to make an app using shiny such that I allow the user to choose two column names using a select input widget from side panel and then show a bar plot using those two columns from a dataset of my choice currently loaded in the environment. The problem is that my dataset has all the columns as categorical character vectors and thus first I have to make a two column table using the table command. So I need to get the name from input and use it in table command but its not happening.

I am attaching my dataset, the ui.r and server.r.

Any help will be much appreciated.

thanks..
smpl.csv
server.R
ui.R

Tyler Hunt

unread,
Apr 2, 2014, 5:14:12 PM4/2/14
to shiny-...@googlegroups.com
I am not sure what you are after but I think this should give you a good start.

#-server.R

smpl<-read.csv("smpl.csv")

shinyServer(function(input, output) {
    
  output$smplTab<-renderDataTable({
    smpl[c(input$cname1, input$cname2)]
  }, options = list(aLengthMenu = c(5, 30, 50), iDisplayLength = 5))
  
  output$myplot<-renderPlot({        
    plot(smpl[c(input$cname1, input$cname2)])
  })

})

#-ui.R

shinyUI(fluidPage(
  titlePanel("Road Accident Analysis")
  ,sidebarPanel(
      selectInput(inputId="cname1",choices=names(smpl),label="Variable1")
      ,selectInput(inputId="cname2",choices=names(smpl),label="Variable2")
      )                    
  ,mainPanel(
    dataTableOutput("smplTab")
    ,plotOutput("myplot")
    )
  )
)
Reply all
Reply to author
Forward
0 new messages