Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何在shiny中呈现单选按钮中的文本字段?_R_Shiny_Radio Button - Fatal编程技术网

R 如何在shiny中呈现单选按钮中的文本字段?

R 如何在shiny中呈现单选按钮中的文本字段?,r,shiny,radio-button,R,Shiny,Radio Button,我需要转换列表中当前代码不运行的选项。函数tr在.csv字典中完成从一个术语到另一个术语的翻译 radioButtons( "enc", renderText({tr("Select encoding in case your data presents strange characters:")}), choices = c( renderText({tr("Automatic"

我需要转换列表中当前代码不运行的选项。函数tr在.csv字典中完成从一个术语到另一个术语的翻译

radioButtons(
              "enc",
              renderText({tr("Select encoding in case your data presents strange characters:")}),
              choices = c(
                renderText({tr("Automatic")}) = "unknown",
                "UTF-8" = "UTF-8",
                "Windows" = "Latin-1"
              ),
              selected = "unknown",
              inline = TRUE
            )
目前的结果是:

Error in source("server/body.R", local = TRUE) : 
server/body.R:86:48: unexpected '='
                 choices = c(
                 renderText({tr("Browse")}) =
                                               ^

一个可复制的例子将非常有用。让我们快速入门,让您确保答案符合您的要求

如果要使用动态ui元素,应该使用renderUI

你也应该仔细检查一些基础知识,。。。renderText生成和输出,不应在其他渲染函数中使用

我用以下方法模拟了tr功能:
tr尝试输出$automaticchoice
library(shiny)

tr <- function(name) return(paste("TR:", name))

ui <- fluidPage(
  uiOutput("radio"),
  plotOutput("distPlot")
)

server <- function(input, output) {

  output$radio <- renderUI({
    opt <- c("Normal" = "norm",
             "Uniform" = "unif",
             "Log-normal" = "lnorm",
             "Exponential" = "exp")
    names(opt)[1] <- tr("Normal")
    label <-  tr("Distribution type:")

    radioButtons("dist", label, opt)
  })  

  output$distPlot <- renderPlot({
    dist <- switch(input$dist,
                   norm = rnorm,
                   unif = runif,
                   lnorm = rlnorm,
                   exp = rexp,
                   rnorm)

    hist(dist(500))
  })
}

shinyApp(ui, server)