R 重置操作按钮以在屏幕中多次显示modaldialog
我正在使用一个仪表板,如果用户需要一些额外的信息,我需要一个帮助按钮来显示一些信息。我希望能够根据需要多次点击“帮助”按钮。现在,我在多个选项卡上使用相同的actionButton作为帮助,但是modalDialog只有在第一次单击按钮后才会显示。如何重置actionButton,以便根据需要多次显示modalDialog 下面是可执行代码R 重置操作按钮以在屏幕中多次显示modaldialog,r,shiny,shinydashboard,R,Shiny,Shinydashboard,我正在使用一个仪表板,如果用户需要一些额外的信息,我需要一个帮助按钮来显示一些信息。我希望能够根据需要多次点击“帮助”按钮。现在,我在多个选项卡上使用相同的actionButton作为帮助,但是modalDialog只有在第一次单击按钮后才会显示。如何重置actionButton,以便根据需要多次显示modalDialog 下面是可执行代码 library(shiny) library(shinythemes) library(shinydashboard) library(tidyverse)
library(shiny)
library(shinythemes)
library(shinydashboard)
library(tidyverse)
options(warn=-1)
data(iris)
data(mtcars)
tabset1 = tabsetPanel(id = "mtcars",
tabPanel(id = "mtplots","mtcars plots",
fluidRow(actionButton("helpme", "?????"), box(title = "Plot1", plotOutput("mtcarsplot1"))
)),
tabPanel(id = "mttable","MTcars tables",
fluidRow(box(title = "Table 1", tableOutput("mtcarstable1")))
))
tabset2 = tabsetPanel(id = "iris",
tabPanel(id = "iris","iris plots",
fluidRow(actionButton("helpme", "?????"), box(title = "Plot1", plotOutput("irisplot1"))
)),
tabPanel(id = "mttable","iris tables",
fluidRow(box(title = "Table 1", tableOutput("iristable1")))
))
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
menuItem("MTCARS", tabName = "mt", icon = icon("user-tie")),
selectInput("mtvar", "Choose a variable", choices = colnames(mtcars)),
sliderInput("mtlines", "Number of lines", 1,50,10),
menuItem("IRIS", icon = icon("envelope-open-text"), tabName = "ir"),
selectInput("irvar", "Choose a variable", choices = colnames(iris)),
sliderInput("irislines", "Number of lines", 1,50,10)
)
),
dashboardBody(
tabItems(
tabItem("ir", tabset2),
tabItem("mt", tabset1)
)
)
)
# Begin Server ----------------------------------------------
server <- function(input, output, session) {
observeEvent(input$helpme, {
showModal(modalDialog(
title = "What is the meaning of life?",
"THE MEANING OF LIFE IS 42",
easyClose = TRUE,
footer = NULL
))
})
output$mtcarsplot1=renderPlot({
ggplot(mtcars, aes_string(x = input$mtvar)) + geom_histogram()
})
output$irisplot1=renderPlot({
ggplot(iris, aes_string(x = input$irvar)) + geom_histogram()
})
output$mtcarstable1=renderTable({
head(mtcars, input$mtlines)
})
output$iristable1=renderTable({
head(iris, input$irislines)
})
}
shinyApp(ui, server)
库(闪亮)
图书馆(shinythemes)
图书馆(shinydashboard)
图书馆(tidyverse)
选项(警告=-1)
数据(iris)
数据(mtcars)
tabset1=tabsetPanel(id=“mtcars”,
选项卡面板(id=“mtplots”,“mtcars plots”,
fluidRow(操作按钮(“帮助”、“打印”)框(title=“Plot1”,plotOutput(“mtcarsplot1”))
)),
tabPanel(id=“mttable”,“MTcars表”,
fluidRow(框(title=“表1”,tableOutput(“mtcarstable1”))
))
tabset2=tabsetPanel(id=“iris”,
选项卡面板(id=“iris”,“iris绘图”,
fluidRow(操作按钮(“帮助”、“打印”)框(title=“Plot1”,plotOutput(“irisplot1”))
)),
tabPanel(id=“mttable”,“iris表”,
fluidRow(框(title=“Table 1”,tableOutput(“iristable1”))
))
ui闪亮,而且没有任何警告。
这是因为在两个选项卡中使用了输出helpme
。
解决方法是创建两个不同的helpme
:
library(shiny)
library(shinythemes)
library(shinydashboard)
library(tidyverse)
options(warn=-1)
data(iris)
data(mtcars)
tabset1 = tabsetPanel(id = "mtcars",
tabPanel(id = "mtplots","mtcars plots",
fluidRow(actionButton("helpme1", "?????"), box(title = "Plot1", plotOutput("mtcarsplot1"))
)),
tabPanel(id = "mttable","MTcars tables",
fluidRow(box(title = "Table 1", tableOutput("mtcarstable1")))
))
tabset2 = tabsetPanel(id = "iris",
tabPanel(id = "iris","iris plots",
fluidRow(actionButton("helpme2", "?????"), box(title = "Plot1", plotOutput("irisplot1"))
)),
tabPanel(id = "mttable","iris tables",
fluidRow(box(title = "Table 1", tableOutput("iristable1")))
))
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
menuItem("MTCARS", tabName = "mt", icon = icon("user-tie")),
selectInput("mtvar", "Choose a variable", choices = colnames(mtcars)),
sliderInput("mtlines", "Number of lines", 1,50,10),
menuItem("IRIS", icon = icon("envelope-open-text"), tabName = "ir"),
selectInput("irvar", "Choose a variable", choices = colnames(iris)),
sliderInput("irislines", "Number of lines", 1,50,10)
)
),
dashboardBody(
tabItems(
tabItem("ir", tabset2),
tabItem("mt", tabset1)
)
)
)
# Begin Server ----------------------------------------------
server <- function(input, output, session) {
observeEvent(input$helpme1, {
showModal(modalDialog(
title = "What is the meaning of life?",
"THE MEANING OF LIFE IS 42",
easyClose = TRUE,
footer = NULL
))
})
observeEvent(input$helpme2, {
showModal(modalDialog(
title = "What is the meaning of life?",
"THE MEANING OF LIFE IS 42",
easyClose = TRUE,
footer = NULL
))
})
output$mtcarsplot1=renderPlot({
ggplot(mtcars, aes_string(x = input$mtvar)) + geom_histogram()
})
output$irisplot1=renderPlot({
ggplot(iris, aes_string(x = input$irvar)) + geom_histogram()
})
output$mtcarstable1=renderTable({
head(mtcars, input$mtlines)
})
output$iristable1=renderTable({
head(iris, input$irislines)
})
}
shinyApp(ui, server)
库(闪亮)
图书馆(shinythemes)
图书馆(shinydashboard)
图书馆(tidyverse)
选项(警告=-1)
数据(iris)
数据(mtcars)
tabset1=tabsetPanel(id=“mtcars”,
选项卡面板(id=“mtplots”,“mtcars plots”,
fluidRow(操作按钮(“helpme1”,“Plot1”)框(title=“Plot1”,plotOutput(“mtcarsplot1”))
)),
tabPanel(id=“mttable”,“MTcars表”,
fluidRow(框(title=“表1”,tableOutput(“mtcarstable1”))
))
tabset2=tabsetPanel(id=“iris”,
选项卡面板(id=“iris”,“iris绘图”,
fluidRow(操作按钮(“helpme2”,“Plot1”)框(title=“Plot1”,plotOutput(“irisplot1”))
)),
tabPanel(id=“mttable”,“iris表”,
fluidRow(框(title=“Table 1”,tableOutput(“iristable1”))
))
用户界面