3
votes

I have a problem for design a nested input/output app. (I have also tried to post this question to shiny-discuss. However, it would be automatically deleted when I post. Why?)

My app can be simplified as the following steps:

  1. Input dataset by textarea. i.e.: input$textarea.in

  2. Load dataset and show the name list of the imported dataset. User could select data by selectInput. i.e: uiOutput("choosedata")

  3. Compute the range of selected data and then display a sliderInput. i.e.: uiOutput("range")

  4. Finally, compute the square of value selected by sliderInput. i.e.:verbatimTextOutput("range.out")

That is:

input => uiOutput => uiOutput => output
          (work!)     (work!)    (error!)

The error will happen at step 4 after changing imported dataset. To be more specific, the initial input format is:

Data.A 1 2 3 4 5
Data.B 6 7 8 9 10 11

Another input format is:

Data.C 1 3 5 7
Data.D 2 4 6 8

Steps 2 and 3 would automatically change, but step 4 wont. How to fix it?

Best

Note that the online app and code are following:

http://glimmer.rstudio.com/tchsieh/myapp/

#=========================
#ui.R
#=========================
library(shiny)
shinyUI(pageWithSidebar(  
  headerPanel("Title"),
  sidebarPanel(
    p("Text Area:"),
    tags$textarea(id="textarea.in", rows=3, "Data.A 1 2 3 4 5 \nData.B 6 7 8 9 10 11"),
    uiOutput("choosedata"),
    uiOutput("range")
  ),

  mainPanel(    
    h2("Test"),

    h3("Raw Data (step1: work!)"),
    verbatimTextOutput("textarea.out"),

    h3("Range of the selected data (step2: work!)"),
    verbatimTextOutput("summary"),

    h3("Squared of the selected value (step3:error when change Text area)"),
    verbatimTextOutput("range.out")


  )
))

#=========================
#server.R
#=========================
library(shiny)
shinyServer(function(input, output) {
  loadPaste <- reactive({
    text <- input$textarea.in
    temp <- lapply(readLines(textConnection(text)), function(x) scan(text = x, what='char'))
    out <- list()
    out.name <- 0
    for(i in seq_along(temp)){
      out.name[i] <- temp[[i]][1]
      out[[i]] <- as.numeric(temp[[i]][-1])
    }
    names(out) <- t(data.frame(out.name))
    out
  })

  output$textarea.out <- renderPrint({
    loadPaste()
  })

  output$choosedata <- renderUI({
    dataname <- names(loadPaste())  
    dataList <- list()
    for(i in seq_along(dataname)){
      dataList[[i]] <- dataname[i]
    }
    selectInput("dataset", "Select dataset:", choices  = dataList, selected = dataList[1])
  })

  output$summary <- renderPrint({
    out <- loadPaste()
    id <- which(names(out) == input$dataset)
    mydata <- out[[id]]
    range(mydata)

  })

  output$range <- renderUI({
    out <- loadPaste()
    id <- which(names(out) == input$dataset)
    mydata <- out[[id]]
    sliderInput("range.in", "Selecte a value in the range of data", min=min(mydata), value=mean(mydata), max=max(mydata), step=diff(range(mydata))/10)
  })

  output$range.out <- renderPrint({
    (input$range.in)^2
  })

})
1
The problem had been solve by use "tryCatch()" in output$choosedata and output$range.user2179862
You should then add that as an answer, so people can find it more easily.Manoel Galdino

1 Answers

3
votes

This was a bug in Shiny that has been fixed in this commit. Thanks for the report!

(Your repeated attempts to post to shiny-discuss were all categorized as spam by Google Groups. I have un-spammed and answered your most recent post, and marked you as a safe sender so hopefully this won't happen again. Sorry for the inconvenience!)