[英]Shiny - RStudio: conditionalPanel does not work when the condition is .Platform$OS.type
Shiny 顯示所有內容,即使條件不滿足,例如.Platform$OS.type == 'windowsxxx'。 由於我使用 window,所以 command.Platform$OS.type 將返回“windows”,而 condition.Platform$OS.type == 'windowsxxx' 應該為 FALSE,但 shiny 似乎沒有評估此條件並顯示其中的所有內容條件面板。 示例代碼如下,每一個建議都非常感謝
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
conditionalPanel(
condition = ".Platform$OS.type == 'windowsxxx'",
sliderInput("breakCount", "This is a conditional sliderInput", min=1, max=1000, value=10)
)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
}
# Run the application
shinyApp(ui = ui, server = server)
如果您將.Platform$OS.type
作為字符串傳遞給conditionalPanel
的condition
參數,它需要一個 JavaScript 表達式 - 它不會被 R 執行。 請檢查以下內容:
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
conditionalPanel(
condition = sprintf("'%s' == 'windowsxxx'", .Platform$OS.type),
sliderInput("breakCount", "This is a conditional sliderInput", min=1, max=1000, value=10)
)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
}
# Run the application
shinyApp(ui = ui, server = server)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.