我在仪表板上有3个框。当将radioButton
选择为“ P3G”时,box1和box3应该出现,即隐藏box2。当选择radiobutton
作为“选择文件”时,应该出现box2和box3。我有以下使用Shinyjs的代码,但是它无法按要求工作,即未隐藏observeEvent
中编码的完整盒子内容。有帮助吗?
sidebar <- dashboardSidebar(width=200,
sidebarMenu(id="tabs",
menuItem("Input File", tabName =
"tab1",icon = icon("fas fa-file"))))
body <- tabItem(tabName = "tab1",value="file_nput",h2("Select file"),
fluidRow(useShinyjs(),
radioButtons("file_rd",label= "Chose Dataset:",
choices = list("P3G","Chose File"),selected = "P3G"),
box( id ="box1",title = "Default Sample", width = 7, status = "info",
tabPanel("Sample Info",value="p3_samples",
DT::dataTableOutput("p3_table"))),
box(id= "box2", title = "Uploaded Sample", width = 7, status = "info",
tabsetPanel(id = "sam_tab",
tabPanel("Upload", value="upload_file",
fileInput(inputId ="FILE",label = "Upload file",multiple=FALSE,
accept = c(".txt")),
checkboxInput('header', label = 'Header', TRUE),
actionButton("createdb","Create DB")),
tabPanel("File Info",value="samples",tableOutput("summary"),icon = icon("info"),
DT::dataTableOutput("full_table"),actionButton("upload","Proceed")))),
box(id = "box3" ,status = "info", width = 5,
tabBox(id = "infobox", height = "100%", width = "100%",
tabPanel("Instructions",h4("Instructions for uploading valid input file"))))))
ui<- shinyUI(dashboardPage(dashboardHeader(title = "TestApp", titleWidth = 150),sidebar,dashboardBody(tabItems(body))))
server <- function(input, output, session) {
observeEvent(input$file_rd, {
if (input$file_rd == "P3G") {
shinyjs::hide(id = "box2", anim=TRUE)
}else {
shinyjs::hide(id = "box1",anim=TRUE)
}
})
}
shinyApp(ui=ui, server=server)
答案 0 :(得分:0)
您可以简单地使用
{{3}}
因此box1的conditionalPanel将如下所示:
conditionalPanel('input.file_rd === "P3G"', box(id = 'box1', ...)
,对于box2和box3:
conditionalPanel('input.file_rd != "P3G"', box(id = 'box2', ...), box(id = 'box3', ...)