我想将此代码保存为代码片段:

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      textOutput("panel")
    ),
    mainPanel(
      tabsetPanel(
        id = "tabset",
        tabPanel("panel 1", "one"),
        tabPanel("panel 2", "two"),
        tabPanel("panel 3", "three")
      )
    )
  )
)
server <- function(input, output, session) {
  output$panel <- renderText({
    paste("Current panel: ", input$tabset)
  })
}

我用通常的方式做: 工具-全局选项-代码-编辑片段.

snippet my_shiny_tabsetPanel
    ui <- fluidPage(
    sidebarLayout(
    sidebarPanel(
    textOutput("panel")),
    mainPanel(
    tabsetPanel(
    id = "tabset",
    tabPanel("panel 1", "one"),
    tabPanel("panel 2", "two"),
    tabPanel("panel 3", "three")
    ))))
    server <- function(input, output, session) {
    output$panel <- renderText({
    paste("Current panel: ", input$tabset)
    })
    }

然后保存. 当我调用该片段时,我得到:

ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textOutput("panel")),
mainPanel(
tabsetPanel(
id = "tabset",
tabPanel("panel 1", "one"),
tabPanel("panel 2", "two"),
tabPanel("panel 3", "three")
))))
server <- function(input, output, session) {
output <- renderText({
paste("Current panel: ", input)
})
}

请判断output$panelinput$tabset. 发生了什么?

我try 过用\$或用$$逃离$.但没有成功.

推荐答案

提供的解决方案here应该有效.基本上用{2:$}就行了

snippet my_shiny_tabsetPanel
    ui <- fluidPage(
        sidebarLayout(
            sidebarPanel(
                textOutput("panel")),
            mainPanel(
                tabsetPanel(
                    id = "tabset",
                    tabPanel("panel 1", "one"),
                    tabPanel("panel 2", "two"),
                    tabPanel("panel 3", "three")
                ))))
    server <- function(input, output, session) {
        output${2:$}panel <- renderText({
            paste("Current panel: ", input${2:$}tabset)
        })
    }

R相关问答推荐

for循环和if else在R中

有没有一种方法可以在子包上使用‘library()’中的‘exclub’参数?

保存shiny 的代码嗅探器:避免$ Symbol问题

有没有方法将paste 0功能与列表结合起来?

是否有任何解决方案可以优化VSCode中RScript的图形绘制?

如何删除多个.CSV文件的行

如何对数据集进行逆向工程?

如何使用R中的dhrr函数将李克特量表的因子列从长转换为宽?

如何按排序顺序打印一个框架中所有精确的唯一值?

如何利用模型函数在格图中添加双曲/指数曲线

在特定Quarto(reveal.js)幻灯片上隐藏徽标

如何在R中描绘#符号?

如何通过判断数据框的一列来压缩另一列?

迭代到DataFrame列并获得成对的值列表(col1->;col2、col2->;col3、col3->;col4等)的正确方法.

基于R中的间隔扩展数据集行

创建列并对大型数据集中的特定条件进行成对比较的更高效程序

有没有办法定制Plot(allEffects())面板标题?

将列表中的字符串粘贴到R中for循环内的dplyr筛选器中

减少雨云面之间的间距并绘制所有统计数据点

我需要使用ggplot2制作堆叠条形图