R Shiny for loop -
i have problem r shiny code. don´t know how create double loop in shiny values typed in user. says: "error in <-: incompatible types (from closure double) in subassignment type fix" btw: shiny right package me when want create app user inputs?
shinyserver( function(input, output){ sum1 <- reactive(input$sum1) weight1 <- 0.7 weight2 <- 1-weight1 asset1 <- reactive({sum1()*weight1}) asset2 <- reactive({sum1()*weight2}) counter1 <- reactive(input$counter1) counter2 <- reactive(input$counter2) (j in 1:counter1) { start <- reactive(sum1()) (i in 1:counter2) { start <- reactive({asset1()*asset2*rnorm(1, mean <- 0, sd <- 1)}) value1[j] <- start } result1 <- quantile(value1, c(0.01)) output$result1 <- value1 } ) library(shiny) shinyui(fluidpage( titlepanel(title = "simulation"), sidebarlayout( sidebarpanel(("data"), numericinput("sum", "sum:", 0, min=0, max=1000000), numericinput("counter1", "counter1", 0, min=0, max=1000), numericinput("counter2", "counter2", 0, min=0, max=1000), submitbutton("submit")), mainpanel(("results:"), textoutput("result1"), ) ) ))
thank help!
your code had few problems: commas, unclosed brackets.. think missing bracket @ shinyserver
reason why server wasn't responding user.
another thing passed input
s reactive
s. can use input
values directly. , @user3949008 said, don't know if can define reactive
in loop. here 1 possible code:
server<-shinyserver( function(input, output) { weight1 <- 0.7 weight2 <- 1 - weight1 asset1 <- reactive({ input$sum * weight1 }) asset2 <- reactive({ input$sum * weight2 }) output$result <- rendertext({ (j in 1:input$counter1) { start <- input$sum (i in 1:input$counter2) { start <- asset1() * asset2() * rnorm(1, mean=0, sd=1) value1 <- start } result1 <- quantile(value1, c(0.01)) outputresult1 <- value1 } paste("results:", outputresult1) }) } ) library(shiny) ui <- shinyui( fluidpage( titlepanel(title = "simulation"), sidebarlayout( sidebarpanel( "data", numericinput("sum", "sum:", 0, min=0, max=1000000), numericinput("counter1", "counter1:", 0, min=0, max=1000), numericinput("counter2", "counter2:", 0, min=0, max=1000) ), mainpanel( textoutput("result") ) ) ) ) shinyapp(ui,server)
Comments
Post a Comment