保存闪亮的代码片段:转义 $ 符号问题

问题描述 投票:0回答:1

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

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$panel
input$tabset
。 发生什么事了?

我尝试使用

$
或使用
\$
来逃避
$$
。但没有成功。

r shiny
1个回答
0
投票

中提供的解决方案应该有效:

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)
        })
    }
© www.soinside.com 2019 - 2024. All rights reserved.