r - Isuue with renderPlot in my Shiny App -
thanks suggestion. checked question before asked own couldn´t fix problem. define vector var_name<-reactive(input$xcol) , used tabledata[,c("var_name")] input in hist function no success.
i´m building app in user can upload own file , make analysis. manage update variable´s names in selectinput each user upload different file. issue can´t pass variable selected in selectinput build histogram. how pass variable selected input histogram? here ui.r code. once execute code error in app "object of type 'closure' not subsettable". advice please? thanks
library(shiny) ui<-fluidpage( titlepanel(title = "my app"), sidebarlayout( sidebarpanel( fileinput('file1', 'cargar archivo', accept = c( 'text/csv', 'text/comma-separated-values', 'text/tab-separated-values', 'text/plain', '.csv', '.tsv' ) ), checkboxinput('header', '¿contiene encabezado?', true), radiobuttons('sep', 'delimitador', c(comma=',', "punto y coma"=';', tab='\t'), ','), radiobuttons('quote', 'quote', c(ninguna='', 'dobles'='"', 'simples'="'"), '"'), radiobuttons('resume', 'summary', c('individual', 'múltiple'), selected = "múltiple", inline = true), conditionalpanel("input.resume === 'individual'", selectinput('xcol', 'variable x', ""), sliderinput("bins","seleccione el número de clases",min=5, max = 15, value = 6), radiobuttons("color","seleccione un color", c("amarillo","azul","rojo","gris"), selected = "azul", inline = true) ) ), mainpanel(h3("muestra del archivo cargado:"), tableoutput('contents'), verbatimtextoutput("summary"), plotoutput("histog") ) ) ) server<-function(input, output, session) { tabledata <- reactive({ infile <- input$file1 if (!is.null(infile)){ read.csv(infile$datapath, header=input$header, sep=input$sep, quote=input$quote) } else { return(null) } }) observe({ updateselectinput( session, "xcol", choices=names(tabledata())) }) var_name<-reactive(input$xcol) output$contents <- rendertable({ head(tabledata()) }) output$summary <- renderprint({ summary(tabledata()) }) output$histog<-renderplot({ hist(tabledata[,c("var_name")],breaks= seq(0,10,l=input$bins+1), col(input$color)) }) } shinyapp(ui = ui, server = server)
there several issues shiny app:
to recognized, colors should coded way:
c(amarillo="yellow",azul="blue",rojo="red",gris="grey")the
var_nameshould handlenullvar_name<-reactive({ if(input$xcol!="") input$xcol else null })the reactive values should used parenthesis:
tabledata() var_name()
this produces error
color parameter should written way:
col=input$coloryou should check whether reactive values
nullor notif(!is.null(tabledata())&&!is.null(var_name())) hist(tabledata()[,var_name()],breaks= seq(0,10,l=input$bins+1), col=input$color)
Comments
Post a Comment