Hide renderPrint Pre Tag Exiting a brilliant application in R

I am developing a Shiny application in R. For some parts of the output, renderPrintI would like the shiny user interface to not display anything. A kind of hidden option for pre or div tags in the HTML5 example below:

http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_global_hidden

Below is my brilliant sample code. Short explanation: you can use the drop-down menu to select one of two variables (factor variable or continuous variable). If you select a factor variable, I want to show the header and output table. If you choose a continuous variable, I don't want to see anything. Right now, the heading disappears if you insert an empty string ""as a return in renderText. However, I do not know how to get renderPrintso as not to show anything. I tried:

  • "". Doesn't work as it returns the actual empty string
  • NULL. It does not work, since it returns a NULL string
  • invisible(). Best so far, but still doesn't work, as it returns a window with a gray formatted one.

, . Shiny ui.r server.r, : ()

##
## Start shiny UI here
##
shinyUI(pageWithSidebar(
headerPanel("Shiny Example"),
    sidebarPanel(
        wellPanel(
        selectInput(    inputId = "variable1",label = "Select First Variable:", 
                choices = c("Binary Variable 1" = "binary1",
                "Continuous Variable 1" = "cont1"),
                selected = "Binary Variable 1"
        )
        )


),
mainPanel(
h5(textOutput("caption2")),
verbatimTextOutput("out2")
)
))

##
## Start shiny server file and simulated data here
##
binary1 <- rbinom(100,1,0.5)
cont1   <- rnorm(100)
dat <- as.data.frame(cbind(binary1, cont1))
dat$binary1 <- as.factor(dat$binary1)
dat$cont1 <- as.numeric(dat$cont1)

library(shiny)

shinyServer(function(input, output) {

inputVar1 <- reactive({
parse(text=sub(" ","",paste("dat$", input$variable1)))
})

output$caption2 <- renderText({
if ( (is.factor(eval(inputVar1()))==TRUE) ) {
caption2 <- "Univariate Table"
} else {
if ( (is.numeric(eval(inputVar1()))==TRUE) ) {
caption2 <- ""
}
}
})

output$out2 <- renderPrint({
if ( (is.factor(eval(inputVar1()))==TRUE) ) {
table(eval(inputVar1()))
} else {
if ( (is.numeric(eval(inputVar1()))==TRUE) ) {
invisible()
} 
}
})
})

...

  • renderText / , renderPrint? , pre tag; div?
  • HTML (upfront, )... ? pre div ( , IE). - ? CSS ..
  • , - ( 2. ), / renderPrint ? ?

Btw... R: version.string R version 3.0.1 (2013-05-16), {R package version 0.6.0}. .

+4
1

, , : Ui:

library(shiny)
 ui <- fluidPage(pageWithSidebar(
         headerPanel("Shiny Example"),
          sidebarPanel(
           wellPanel(
           selectInput(inputId = "variable1",label = "Select First Variable:", 
                  choices = c("Binary Variable 1" = "binary1",
                              "Continuous Variable 1" = "cont1"),
                  selected = "Binary Variable 1"
  )
 )
),
   mainPanel(
     h5(textOutput("caption2")),
     verbatimTextOutput("out2", placeholder=TRUE)
 )
 ))

:

binary1 <- rbinom(100,1,0.5)
cont1   <- rnorm(100)
dat <- as.data.frame(cbind(binary1, cont1))
dat$binary1 <- as.factor(dat$binary1)
dat$cont1 <- as.numeric(dat$cont1)

server <- (function(input, output) {
  inputVar1 <- reactive({
   parse(text=sub(" ","",paste("dat$", input$variable1)))
  })

 output$caption2 <- renderText({
   if ((is.factor(eval(inputVar1()))==TRUE) ) {
     caption2 <- "Univariate Table"
   } else {
     if ((is.numeric(eval(inputVar1()))==TRUE) ) {
       caption2 <- "Continous"
    }
  }
})

 output$out2 <- renderPrint({
   if ((is.factor(eval(inputVar1()))==TRUE) ) {table(eval(inputVar1()))} 
 })
})

:

shinyApp(ui = ui, server = server)
0

All Articles