r - Shiny: Passing on text with a space to chart does not work, but it works without a space -
my shiny script gets input drop down list. based on this, set (on server side) specific string (in reactive) should displayed in chart (for example x axis title). works if string contains no spaces, no string shown in chart if contains spaces.
how can accept string?
here's code (i modified 1 of example shiny tutorial keep simple possible):
# server.r # here string set depending on chosen user shinyserver(function(input, output, session) { label1_new <- reactive({ if (input$variable1=="pp_pmw") {label1_new <- "pp pmw"} if (input$variable1=="perc_pp*100") {label1_new <- "pp percent"} if (input$variable1=="formality") {label1_new <- "formality"} }) label1_new2 <- rendertext({label1_new()}) output$distplot <- renderplot({ x <- faithful[, 2] # old faithful geyser data bins <- seq(min(x), max(x), length.out = input$bins + 1) # draw histogram specified number of bins # xlabel1_new2() contains string above hist(x, breaks = bins, col = 'darkgray', border = 'white', xlab=label1_new2()) }) }) # ui.r library(shiny) shinyui(fluidpage( # application title titlepanel("hello shiny!"), # sidebar slider input number of bins sidebarlayout( sidebarpanel( selectinput("variable1", "circle size:", list("pp pmw" = "pp_pmw", "pp percent" = "perc_pp*100", "formality" = "formality")), sliderinput("bins", "number of bins:", min = 1, max = 50, value = 30) ), # show plot of generated distribution mainpanel( plotoutput("distplot") ) ) ))
rendertext use ui.r, not creating strings used in server.r
# server.r # here string set depending on chosen user shinyserver(function(input, output, session) { label1_new <- reactive({ if (input$variable1=="pp_pmw") return("pp pmw") if (input$variable1=="perc_pp*100") return("pp percent") if (input$variable1=="formality") return("formality") }) output$distplot <- renderplot({ x <- as.numeric(unlist(faithful[, 2])) # old faithful geyser data bins <- seq(min(x), max(x), length.out = input$bins + 1) # draw histogram specified number of bins hist(x, breaks = bins, col = 'darkgray', border = 'white', xlab=label1_new()) }) }) (same ui.r)
Comments
Post a Comment