R shiny error: Problems with a reactive function -
i making interactive graph in r studio new shiny markdown. thought create active page have 2 input fields determine size of a, size of b , left size of c. input in percentage. output graph line , bars, works. however, have 2 problems.
the sec input has dependent of first input, because can never have more 100 percent. the size of , b determined after input given. if input changes, a, b , c has determined again.i quite new r , searched other questions not solve problems. code , how tried solve it:
inputpanel( numericinput("aa", label = "a:", min = 1 , max =100 , value = 80 , step = 1), numericinput("bb", label = "b:", min = 1 , max = 100-input$aa , value = 15 , step = 1) ) this first problem. want sec numeric input reactive on first input. tried next options problem:
numericinput("bb", label = "b:", min = 1 , max = observe(100-input$aa,suspended= true) , value = 15 , step = 1) this did not work. next thing tried is:
numericinput("bb", label = "b:", min = 1 , reactive({max = 100-input$aa}) , value = 15 , step = 1) this gave error. after trying options, find quite logic not work, however, still can not find how solve this.
the sec problem in next code.
###change column b for(i in nrow(df)){reactive({ if(input$aa>df$a[i]){ df$b[i] = "a" } else {if(input$aa+input$bb>df$a[i]){ df$b[i] = "b" }else {df$b[i] = "c"}}})} i want alter value of column b in df. piece of code not give errors, however, not active, not alter column b. tried following:
###change column b shinyserver(function(input, output) { for(i in nrow(df)){reactive({ if(input$large>df$a[i]){ df$b[i] = "a" } else {if(input$aa+input$bb>df$a[i]){ df$b[i] = "b" }else {df$b[i] = "c"}}})}}) this seems ignore code more. tried , quite new r. hope can help me issue.
thanks in advance, edit after comment
shortest programme (in opinion)
--- title: "a" author: "b" date: "6/24/2014" output: html_document runtime: shiny --- ```{r, echo=false} library(ggplot2) library(shiny) df= data.frame(a=c(1:20),b=c(1:20)) df$c=1 #just create sure column c exist. inputpanel( numericinput("aa", label="a", min = 1, max = 100, value =50) , numericinput("bb",label= "b", min = 1, max = 100-input$aa, value = 10) ) df$c <- reactive({ df$c <- input$aa }) renderplot({ ggplot(df) + geom_line(aes(a, b, colour= c )) }) ``` eddy
here illustration using renderui. havent looked @ using shiny in markdown documents im guessing parses document in clever manner allocate appropriate quantities shinyui , server function:
--- title: "a" author: "b" date: "6/24/2014" output: html_document runtime: shiny --- ```{r, echo=false} library(ggplot2) library(shiny) df= data.frame(a=c(1:20),b=c(1:20)) df$c=1 #just create sure column c exist. inputpanel( numericinput("aa", label="a", min = 1, max = 100, value = 50) , uioutput('test') ) output$test <- renderui({ numericinput("bb",label= "b", min = 1, max = 100-as.integer(input$aa), value = 10) }) myreact <- reactive({ out <- df out$b <- out$b + input$aa out }) renderplot({ ggplot(myreact()) + geom_line(aes(a, b, colour= c )) }) ``` r shiny
No comments:
Post a Comment