[英]Only show these panels if the plot type is a barplot. R shiny
我希望用户以 select 的类型 plot 来显示。
如果 plot 的类型是“条形图”,则应出现新的选择变量。 在这种情况下,“分箱”和“休息”。
但是,下面的代码无法正常工作。 在 conditionalPanel 之后不显示新变量。
在这里你有RepEx。
# Shiny
library(shiny)
library(shinyWidgets)
library(shinyjqui)
# Data
library(readxl)
library(dplyr)
library(arules) # Discretization
# Plots
library(ggplot2)
not_sel <- "Not Selected"
# main page display in the shiny app where user will input variables and plots will be displayed
main_page <- tabPanel(
title = "Plotter",
titlePanel("Plotter"),
sidebarLayout(
sidebarPanel(
title = "Inputs",
fileInput("xlsx_input", "Select XLSX file to import", accept = c(".xlsx")),
selectInput("num_var_1", "Variable X axis", choices = c(not_sel)),
selectInput("num_var_2", "Variable Y axis", choices = c(not_sel)), uiOutput("binning"),
selectInput("graph", "Choose a graph to view:",
choices = c("Boxplot", "Barplot")), #Choose type of plot to be displayed
# Only show these panels if the plot type is a barplot
conditionalPanel(condition = "graph == 'Barplot'",
checkboxGroupButtons(
inputId = "bin_sce",
label = "Binning Scenario:",
choices = c("Frequency", "Interval"),
direction = "vertical"),
),
conditionalPanel(condition = "graph == 'Barplot'",
radioGroupButtons(
inputId = "breaks",
label = "Breaks",
choices = c("2", "3", "4", "5"),
checkIcon = list(
yes = icon("ok",
lib = "glyphicon"))
)
),
actionButton("run_button", "Run Analysis", icon = icon("play"))
),
mainPanel(
tabsetPanel(
tabPanel(
title = "Plot",
br(),
plotOutput("")
)
)
)
)
)
# User interface
ui <- navbarPage(
main_page
)
# Server
server <- function(input, output){
# Dynamic selection of the data. We allow the user to input the data that they want
data_input <- reactive({
#req(input$xlsx_input)
#inFile <- input$xlsx_input
#read_excel(inFile$datapath, 1)
iris
})
# We update the choices available for each of the variables
observeEvent(data_input(),{
choices <- c(not_sel, names(data_input()))
updateSelectInput(inputId = "num_var_1", choices = choices)
updateSelectInput(inputId = "num_var_2", choices = choices)
updateSelectInput(inputId = "biomarker", choices = choices)
})
num_var_1 <- eventReactive(input$run_button, input$num_var_1)
num_var_2 <- eventReactive(input$run_button, input$num_var_2)
biomarker <- eventReactive(input$run_button, input$biomarker)
}
# Connection for the shinyApp
shinyApp(ui = ui, server = server)
如您所见,没有显示任何新内容。
您必须在条件中添加"input.graph == 'Barplot'"
。 这些条件不是 R 代码而是 JS 作为字符串传递,然后由 function 本身转换。
# Only show these panels if the plot type is a barplot
conditionalPanel(condition = "input.graph == 'Barplot'",
checkboxGroupButtons(
inputId = "bin_sce",
label = "Binning Scenario:",
choices = c("Frequency", "Interval"),
direction = "vertical"),
),
conditionalPanel(condition = "input.graph == 'Barplot'",
radioGroupButtons(
inputId = "breaks",
label = "Breaks",
choices = c("2", "3", "4", "5"),
checkIcon = list(
yes = icon("ok",
lib = "glyphicon"))
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.