[R] Fwd: Widgets under renderUI Shiny

John Murtagh john9427 at gmail.com
Sun Jun 25 00:47:12 CEST 2017


Hi All,

I am not sure if this is a relevant platform to ask but I have tried other
more related platforms and haven't had any luck so i thought i would try my
luck here.

Basically I want to generate a selectInput widget with a conditional under
renderUI in Shiny.

The number of widgets generated will depend on the number of variables a
user selects. Try as I may I have not been able to get this to work and
have had no luck in getting any help on other platforms hence why i am
asking here on the odd chance someone may be able to share his knowledge
and explain what it is I am doing wrong or a workaround that I can apply.
Below is the code I have so far (please feel free to criticize the code, I
am new to R/programming with no background). Thanks

 library(shiny)


ui= fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectizeInput(inputId= "invar", label= "invar",
                     choices= names(iris),
                     selected= names(iris)[1],
                     multiple=T),
      uiOutput("invarpdf")

    ),
    mainPanel(
      tableOutput("tab")
    )
  ))


server= function(input, output,session) {

  sorted <-  reactive({
    data <- iris[ ,c(input$invar)]
    #print(input$invar)
    data})

  output$invarpdf<-renderUI({
    numvar<- length(input$varnames)
     {
      selectInput(inputId=paste0("distinvar",input$invar),paste0("Please
Select Probability Distribution of ", input$invar),
                  choices = c("Normal","Uniform","Triangular"))
      conditionalPanel(condition = "input.distinvarpdf=='Normal'",
                       textInput("invarpdfmean","Please Select Input
Variable Mean:",0.25),
                       textInput("invarpdfsd","Please Select Input
Variable Standard Deviation", 0.02))
      conditionalPanel(condition = "input.distinvarpdf=='Uniform'",
                       textInput("invarpdfmin","Please Select Minimum
Input Variable Value:",0.18),
                       textInput("invarpdfmax","Please Select Maximum
Input Variable Value", 0.3))
      conditionalPanel(condition = "input.distinvarpdf=='Triangular'",
                       textInput("invarpdfmin","Please Select Minimum
Input Variable Value:",0.18),
                       textInput("invarpdfmax","Please Select Maximum
Input Variable Value:", 0.3))
      conditionalPanel(condition = "input.distinvarpdf=='Log Normal'",
                       textInput("invarpdfmeanlog","Please Select Mean
Log of Input Variable:",0.18),
                       textInput("invarpdfsdlog","Please Select
Standard Deviation Log of Input Variable:", 0.3))
    }})

  output$MonteCarlo <- renderPlot({
    set.seed(1)


    n <- input$sampleSize




    if(distinvarpdf=="Normal"){

      invarpdfVec <- rnorm(n,mean = as.numeric(input$invarpdfmean),sd=
as.numeric(input$invarpdfsd))
    }
    if(distinvarpdf=="Uniform"){

      invarpdfVec <- runif(n,min = as.numeric(input$invarpdfmin),max =
as.numeric(input$invarpdfmax))
    }
    if(distinvarpdf=="Triangular"){

      invarpdfVec <- rltriangle(n,a = as.numeric(input$invarpdfmin),b
= as.numeric(input$invarpdfmax))
    }
    if(distinvarpdf=="Log Normal"){

      invarpdfVec <- rlnorm(n,meanlog =
as.numeric(input$invarpdfmeanlog),sdlog =
as.numeric(input$invarpdfsdlog))
    }




    h<- hist(distinvarpdf,


...

[Message clipped]

	[[alternative HTML version deleted]]



More information about the R-help mailing list