Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check for linearity using a dynamic variable by a shiny widget

I want to use every time a different variable to put inside the plot() function to check for linearity using a shiny widget but I get: variable lengths differ (found for 'input$var')

## app.R ##
library(shiny)
library(shinydashboard)
library(shinyjs)
library(htmlwidgets)

ui <- dashboardPage(
  dashboardHeader(
    title="Task Managers' Workload Analysis",
    titleWidth = 400
    
  ),
  dashboardSidebar(
    selectInput("var","Select variable",choices = colnames(diamonds),selected = colnames(diamonds)[1])
  ),
  dashboardBody(
    plotOutput("hist")
  )
)

server <- function(input, output,session) {
  output$hist<-renderPlot({
    plot(price ~ input$var, data=diamonds)
  })
} 

shinyApp(ui, server)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You could either:

plot(eval(parse(text = input$var)) ~ price, data = diamonds)

or

plot(diamonds[[input$var]] ~ price, data = diamonds)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading