Skip to content

Commit

Permalink
Add some tests for character encodings
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Dec 10, 2015
1 parent 788931c commit 76a5424
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/test-encoding/01-symbols/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
library(shiny)
app <- shinyApp(
ui = fluidPage(
"\u2264 and \u2265",
uiOutput("bin_prob_k"),
uiOutput("bin_prob_inequality"),
uiOutput("bin_prob_out"),
plotOutput("pmf")
),
server = function(input, output) {

output$bin_prob_k = renderUI({
numericInput("binom4_k", label = "Number of successes (k)", value = 3,
step = 1, min = 0, max = 10)
})

bin_choices = reactive({
nms = paste("P(X",c("=","\u2264","<","\u2265",">"),input$binom4_k,")",sep="")
return(nms)
})

output$bin_prob_inequality = renderUI({
selectInput("bin_prob_type", label = "Inequality type", choices = bin_choices())
})

output$pmf <- renderPlot({
n=10
prob = 0.4
probs = dbinom(0:n, size=n, prob=prob)
mtext(input$bin_prob_type, side = 3, col = "red", cex = 1.2)
})

output$bin_prob_out = renderUI({
withMathJax(paste0("\\(",input$bin_prob_type,"\\)",sep=""))
})

}
)
2 changes: 2 additions & 0 deletions tests/test-encoding/02-backslash/server.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
function(input, output) {
}
6 changes: 6 additions & 0 deletions tests/test-encoding/02-backslash/ui.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
library(shiny)

tagList(
p("Chinese: 中文"),
helpText("T:\\2_共享区\\11_资料共享\\MO_Task_File")
)
17 changes: 17 additions & 0 deletions tests/test-encoding/test-all.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Assume the working dir is the root dir of the shiny source package, and the
# shiny-examples repo (https://github.com/rstudio/shiny-examples) is under the
# same dir as the shiny package
library(shiny)
apps <- list.files('tests/test-encoding/', '^[0-9]{2}-', full.names = TRUE)
apps <- c(apps, '../shiny-examples/022-unicode-chinese/')
locales <- c('Chinese', 'English')

# Run these apps in the RStudio preview window one by one in different locales.
# Note 022-unicode-chinese may not work well in the English locale (explained at
# https://github.com/rstudio/shiny/pull/968)
for (app in apps) {
for (locale in locales) {
print(Sys.setlocale(locale = locale))
tryCatch(shiny::runApp(app), interrupt = function(e) {})
}
}

0 comments on commit 76a5424

Please sign in to comment.