首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >特殊字符在renderUI中不起作用

特殊字符在renderUI中不起作用
EN

Stack Overflow用户
提问于 2021-04-24 00:22:26
回答 1查看 38关注 0票数 0

我用法语开发出色的应用程序,因此我使用特殊字符,如"é" (带有重音的e)、"ê""Œ"等。但这些特殊字符在renderUI中不起作用。例如,类别Pancréas (带有"é")不能正常工作,除非我删除é并将类别设置为胰腺。如何在renderUI中使用特殊字符?

代码语言:javascript
复制
library(shiny)
library(tidyverse)
TypeOfDisease<-c(rep("Infection",12),rep("Cancer",5),rep("Infection",14),
                 rep("Cancer",9),rep("Infection",8),rep("Cancer",7),rep("Infection",15),rep("Cancer",0),
                 rep("Infection",12),rep("Cancer",18))
Organ<-c(rep("Oesophage",17),rep("Stomach",23),rep("Lung",15),rep("Pancréas",15),rep("Liver",30))
data<-data.frame(TypeOfDisease,Organ)
addmargins(table(data$TypeOfDisease,dataF$Organ))

ui<-fluidPage(
  
  sidebarLayout(
    sidebarPanel(
      selectInput("Organ","Select the organ",
                  choices = c("Total",levels(data$Organ))),
      
      uiOutput("ui"),
    ),
    mainPanel(
      
      fluidRow(
        column(5,tableOutput("table")),
        column(7,
               
               fluidRow(verbatimTextOutput("matrix")),
               fluidRow(verbatimTextOutput("Nrow"))
        )
      )
      
      
      
    )
  )
  
)


server<-function(input,output){
  
  
  output$ui<-renderUI(
    
    switch (input$Organ,
            
            "Total" = selectInput("TypeOfDis","Type of disease",
                                  choices = c("Total","Infection","Cancer")),
            "Oesophage" = selectInput("TypeOfDis","Type of disease",
                                      choices = c("Total","Infection","Cancer")),
            "Stomach" = selectInput("TypeOfDis","Type of disease",
                                    choices = c("Total","Infection","Cancer")),
            "Lung" = selectInput("TypeOfDis","Type of disease",
                                 choices = c("Total","Infection","Cancer")),
            "Pancréas" = selectInput("TypeOfDis","Type of disease",
                                     choices = c("Total")),
            "Liver" = selectInput("TypeOfDis","Type of disease",
                                  choices = c("Total","Infection","Cancer")),
    )
  )
  
  dataFilter<-reactive({
    
    if(input$TypeOfDis=="Total"&input$Organ=="Total"){
      data
    }else {
      
      
      if(input$TypeOfDis=="Total"){
        data[data$Organ==input$Organ,]
      }else if (input$Organ=="Total"){
        data[data$TypeOfDisease==input$TypeOfDis,]
      }else
        data[data$TypeOfDisease==input$TypeOfDis & data$Organ==input$Organ ,]
    
      
      
      } 
    
  })
  
  output$table<-renderTable ({dataFilter()})
  output$matrix<-renderPrint({addmargins(table(data$TypeOfDisease,dataF$Organ))})
  output$Nrow<-renderPrint({nrow(dataFilter())})
  
}



shinyApp(ui,server)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-24 01:04:13

运行上面的示例,我可以正确地显示"é"。我会检查以确保编码设置为允许这些字符的UTF-8之类的格式。我不是编码专家(这可能是一个很深的兔子洞),但我会在解析代码时首先进行检查。例如,我将您的示例复制到一个空白文件中并运行源代码,此命令出现在控制台source('~/.active-rstudio-document', encoding = 'UTF-8', echo=TRUE)

如果已设置,但仍无法正常显示,请在浏览器中启动应用程序并检查页面源代码。确保在head元素中声明了UTF-8。像这样的东西:

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

我能想到的最后一件事就是尝试将HTML codes或Unicode值(\U00E9)直接替换到标签定义中。这篇讨论在R字符串中手动指定Unicode的post可能会有所帮助。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67233620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档