【问题标题】:special symbols in value field of textInputtextInput 的值字段中的特殊符号
【发布时间】:2019-08-22 16:15:56
【问题描述】:

我想在 textInput 小部件的值字段中使用诸如希腊字母和下标之类的东西。我知道如何为标签执行此操作,但同样的事情在该领域不起作用。这是玩具示例

    runApp(list(
  ui = fluidPage(
    uiOutput("txt")
  ),
  server = function(input, output) {
    output$txt <- renderUI({
       textInput("a", 
            label = HTML(" &pi;<sub>0</sub> works here"), 
            value = HTML("but not &pi;<sub>0</sub> here"))

    })    
  }  
))

这会在标签中正确显示希腊字母和下标,但不会在文本字段中显示

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    值不能是html,需要用其他方式输入特殊字符,“π\u2092”有效,

    或者避免知道 π:

    value = paste0(intToUtf8(0x03C0), "\u2092")
    

    注意,它看起来不太好,因为下标被剪掉了:

    library(shiny)
    runApp(list(
      ui = fluidPage(
        textInput("a", 
                  label = HTML(" &pi;<sub>0</sub> works here"), 
                  value = paste0(intToUtf8(0x03C0), "\u2092, works here!")),
        verbatimTextOutput ("txt")
      ),
      server = function(input, output) {
        output$txt <- renderText({
          input$a
    
        })  
    
      }  
    ))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-12
      • 1970-01-01
      • 2020-05-25
      • 2013-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多