r - 在 Shiny 中选择选项时删除滑块
问题描述
我想帮助解决以下问题:
下面的可执行代码显示了插入 excel 文件时的一组条件(可以是任何条件)。您有“是”或“否”选项。如果请求“否”选项,则会出现以下选项:更改过滤器或更改集群编号,如附件中所示。如果我选择更改集群编号的选项,则会显示一个滑块。但是,如果我按 Yes 选项,则应该删除 Slider,但是它没有完成(附加)。因此,我想对此进行调整。
library(shiny)
library(shinythemes)
library(readxl)
df<-structure(list(Properties = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35),
Latitude = c(-23.8, -23.8, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9, -23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9,-23.9),
Longitude = c(-49.6, -49.6, -49.6, -49.6, -49.6, -49.6, -49.6, -49.6, -49.6, -49.6, -49.7, -49.7, -49.7, -49.7, -49.7, -49.6, -49.6, -49.6, -49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6,-49.6),
Waste = c(526, 350, 526, 469, 285, 175, 175, 350, 350, 175, 350, 175, 175, 364, 175, 175, 350, 45.5, 54.6,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350,350)),
class = "data.frame", row.names = c(NA, -35L))
ui <- bootstrapPage(
navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
"Cl",
tabPanel("Solution",
fileInput("data", h3("Import excel")),
sidebarLayout(
sidebarPanel(
conditionalPanel(
"output.fileUploaded == true",
tags$hr(style="border-color: black;"),
tags$p(h3("Are you satisfied?")),
radioButtons( "satisfaction","", choices = list("Yes" = 1,"No " = 2),selected = 1)),
conditionalPanel(
"input.satisfaction == '2'",
selectInput("naosatisf", h4("Choose a option below:"),
choices = c("no option selected" = "","Change the filters" = 1, "Change the cluster number" = 2), selected = "")),
conditionalPanel(
"input.naosatisf == '2'",
sliderInput("Slider", h5(""),
min = 2, max = 31, value = "")),
),
mainPanel(
tabsetPanel(
tabPanel("Solution", plotOutput("ScatterPlot"))))
))))
server <- function(input, output, session) {
v <- reactiveValues(df = NULL, clear = FALSE)
observeEvent(input$data, {
v$df <- read_excel(input$data$datapath)
v$clear <- TRUE
})
output$fileUploaded <- reactive({
v$clear
})
outputOptions(output, "fileUploaded", suspendWhenHidden = FALSE)
}
shinyApp(ui = ui, server = server)
解决方案
我只是移动了一个括号)
,以便您的第三个conditionalPanel
嵌套在您的第二个中。这会给你想要的行为吗?
ui <- bootstrapPage(
navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
"Cl",
tabPanel("Solution",
fileInput("data", h3("Import excel")),
sidebarLayout(
sidebarPanel(
conditionalPanel(
"output.fileUploaded == true",
tags$hr(style="border-color: black;"),
tags$p(h3("Are you satisfied?")),
radioButtons( "satisfaction","", choices = list("Yes" = 1,"No " = 2),selected = 1)),
conditionalPanel(
"input.satisfaction == '2'",
selectInput("naosatisf", h4("Choose a option below:"),
choices = c("no option selected" = "","Change the filters" = 1, "Change the cluster number" = 2), selected = ""),
conditionalPanel(
"input.naosatisf == '2'",
sliderInput("Slider", h5(""),
min = 2, max = 31, value = "")),
)),
mainPanel(
tabsetPanel(
tabPanel("Solution", plotOutput("ScatterPlot"))))
))))
推荐阅读
- mongodb - 将条件添加到最近的值结果
- reactjs - 如何在错误边界中获取 React 组件数据(当前状态、道具等)?
- java - 检查房间数据库android java中是否存在对象
- android - 使用带有颤振的android studio运行时应用程序未启动
- java - 天蓝色应用服务上的 Spring 应用中没有 UTF-8 编码
- git - pip install -e "private_repo" 导致错误,而 git clone "private_repo" 执行 OK
- python - 使用 IPython 使用 argparse 运行模块
- amazon-web-services - 如何在 Fargate 上调试 EKS 而不将日志发送到 Cloudwatch
- git - 如何使用个人访问令牌克隆、拉取和推送存储库?
- c# - C# for Postgres 中的 .CommandText 删除双引号