【发布时间】:2021-08-08 19:05:03
【问题描述】:
当我按下reset按钮时如何插入屏幕清除功能?
非常感谢!
library(shiny)
library(shinythemes)
function.cl<-function(df,date,d1,d2){
df <- structure(
list(date = c("2021-01-01","2021-01-02","2021-01-03","2021-01-04","2021-01-05"),
d1 = c(0,1,4,5,6), d2 = c(2,4,5,6,7)),class = "data.frame", row.names = c(NA, -5L))
}
ui <- fluidPage(
ui <- shiny::navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
br(),
tabPanel("",
sidebarLayout(
sidebarPanel(
selectInput("d1", label = h4("D1"),""),
selectInput("d2", label = h4("D2"),""),
br(),
actionButton("reset", "Reset"),
),
mainPanel(
))
)))
server <- function(input, output,session) {
data <- reactive(function.cl())
observe({
updateSelectInput(session, "d1", label = "D1", unique(data()$d1))
updateSelectInput(session, "d2", label = "D2", unique(data()$d2))
})
observeEvent(input$reset,{
updateRadioButtons(session, "d1", selected = "")
updateRadioButtons(session, "d2", selected = "")
})
}
shinyApp(ui = ui, server = server)
【问题讨论】:
-
你到底想“重置”按钮做什么?
-
运行APP时,两个selectInput中都会出现信息。按重置按钮,我希望删除此信息。
-
所以您希望 D1 和 D2 设置为“”,即使这不是下拉菜单中的有效选项?因为使用 selectInput 你不能选择不在值列表中的项目。
-
我不明白。您更新了问题。现在它已经有了解决方案。
-
对不起梅丁。我调整了代码。我插入了一个重置功能。现在,它重置了屏幕上显示的值,到目前为止还可以。但是,如果我查看 selectinput 选择选项,数字仍然会出现。在这种情况下,我希望这些值不再出现。