I want to control the appearance of a modalDialog depending on the input of a selectInput, what is the best way to do that? I've tried the following code, but conditionalpanel doesn't work within modalDialog. (showing part of the code)
ui<-fluidPage(
selectInput("v1",c("Active_ingredient","Brand_Name"),
actionButton("tabBut", "Select Drug and Event...", style='primary')
)
server<-function(input, output, session) {
dataModal<-function(failed=FALSE){
modalDialog(
conditionalPanel(
condition="input.v1==Active_ingredient",
selectizeInput_p("t1", "Active Ingredient",
choices=c("start typing to search..."="",ing_choices),
HTML( tt('drugname1') ), tt('drugname2'),
placement='bottom')
),
conditionalPanel(
condition="input.v1==Brand_Name",
selectizeInput_p("t1_1", "Name of Drug",
choices=c("start typing to search..."="",drug_choices),
HTML( tt('drugname1') ), tt('drugname2'),
placement='bottom')
),
selectizeInput_p("t2", "Adverse Events",choices= c("Start typing to search"=""),
HTML( tt('eventname1') ), tt('eventname2'),
placement='left'),
numericInput_p('maxcp', "Maximum Number of Change Points", 3, 1, step=1,
HTML( tt('cplimit1') ), tt('cplimit2'),
placement='left'),
footer = tagList(
modalButton("Cancel"),
actionButton("update", "OK")
)
)
}
observeEvent(input$tabBut, {
showModal(dataModal())
})
}
You might try moving the modal dialog to ui.R, using bsModal.See here for an example:
Create a popup dialog box interactive
Hope this helps! Florian
Related
I'm trying to create an Rshiny application and I'm stuck with inserting a common value inside all the tabs of a navbarmenu. When I'm trying it is getting inserted to all the tabs which are not even a part of the navbarMenu.
Can somebody suggest me a solution? than you in advance
This is my code
ui <- fluidPage(
sidebarPanel(
selectInput("variable", "Select an SKU:", materials, selected = '')
),
mainPanel(
navbarPage("DEMAND PREDICTION!",
theme = shinytheme("flatly"),
tabPanel("Home",
h1("Time series forecasting"),
verbatimTextOutput("summary_1")
),
tabPanel("Histogram",
fluidRow(column(3,
wellPanel(selectInput("variable", "Select an SKU:", materials, selected = ''),
selectInput("market", "Select a market:", choices = NULL)
))
),
mainPanel(
plotlyOutput("hist"),
h4("Sales per Country"),plotOutput("map")
)),
navbarMenu("Exploratory Analysis",
tabPanel("Line graph",
plotlyOutput("exploratory")),
tabPanel("Box plot", plotlyOutput("boxplot")),
tabPanel("Seasonal plot", plotlyOutput("seasonal")),
fluidRow(column(3,"hello")))
)))
This is just an overview of my code. Here inside the navbar menu I'm trying to add a common field that can be reflected in all panels within the navbarMenu. Instead it is shown in other tabs which are not even a part of navbarMenu.
I have been trying to develop this tabsetpanel for a while but without success. The goal is to assemble the tabs dynamically. After the user click the search button, the tabs will be assembled from the user's selection in selectizeInput. Each tab will have a specific content. When the user presses the search button again, the tabs must be built again with the information from selectizeInput without duplication.
I appreciate any help.
the result should be like this image:
library(shiny)
ui <- fluidPage(
title = "Examples of DataTables",
sidebarLayout(
sidebarPanel(
selectizeInput(
'state', 'State', choices = state.name, multiple = TRUE
),
actionButton("search", "Search"),
),
mainPanel(
tabsetPanel(
id = 'dataset',
tabPanel("tab1", verbatimTextOutput("tab1"))
)
)
)
)
server <- function(input, output) {
output$tab1 <- renderPrint({
"tab1"
})
}
shinyApp(ui, server)
Well, I figure it out using insertUI and removeUI. To loop the tabsetPanel I used do.call method and voila!!!
I'm working on a Shiny app and I would like to know if it's possible or if anyone else has been able to trigger an observeEvent() by switching between tabPanel().
I have had experience in enabling and disabling the tabPanel() once certain actions are executed thanks to #SriPaladugu code and #DeanAttali shinyjs package but I don't know the extent of these two methods/package when it comes to answering my own question.
I need to trigger an observeEvent() in order to execute removeNotification() and remove any warnings windows when switching between tabs.
The way I pictured of doing this was something like:
observeEvent(input$tabSwitch, {
removeNotification(previous.warning.message)
})
However, there is no way to make switching tabs an eventExpr thus making the code above exectuable
If anyone has done this or has knowledge on how to do this, I would greatly appreciate it.
As already mentioned in the comments you'll have to provide an id to the tabsetPanel.
Here is a working example:
library(shiny)
ui <- fluidPage(
mainPanel(
tabsetPanel(id = "tabSwitch",
tabPanel("Tab 1", br(), "Tab 1 content"),
tabPanel("Tab 2", br(), "Tab 2 content"),
tabPanel("Tab 3", br(), "Tab 3 content")
), br(),
actionButton("warningBtn", "Generate Warning")
)
)
server <- function(input, output, session) {
observeEvent(input$warningBtn, {
showNotification(ui = paste(Sys.time(), " - Warning!"), duration = NULL, closeButton = FALSE, id = "previousWarningMessage", type = "warning")
})
observeEvent(input$tabSwitch, {
print(paste("You clicked tab:", input$tabSwitch))
removeNotification("previousWarningMessage")
})
}
shinyApp(ui, server)
In addition to the default close button, I would like to add a button located on the bottom left of my bsmodal.
I tried:
library(shiny)
library(shinyBS)
ui<-fluidPage(
actionButton("tabBut", "View Table"),
bsModal("modalExample", "Modal Example", "tabBut", size = "large",tags$div(class="modal-footer",tags$button(type="button",class="btn btn-primary mr-auto","data-dismiss"="modal","Done")))
)
server<-function(input, output){
}
shinyApp(ui=ui,server=server)
On way to handle this would be to use shiny showModal and modalDialog as shown in the below example:
library(shiny)
library(shinyBS)
ui<-fluidPage(
actionButton("tabBut", "View Table"),
#bsModal("modalExample", "Modal Example", "tabBut", size = "large",tags$div(class="modal-footer",tags$button(type="button",class="btn btn-primary mr-auto","data-dismiss"="modal","Done")))
)
server<-function(input, output){
observeEvent(input$tabBut, {
showModal(
modalDialog(
title = 'Modal Example',
footer = tagList(
actionButton("done", "Some button for Done"),
modalButton('Close')
)
)
)
})
}
shinyApp(ui=ui,server=server)
i am creating an user registration application which accepts the user inputs like:username,Fullname,Email,contact number.
After clicking create button i am able to display modal message stating user registered . Onclick of close button i want my tabpanel created to reset all the textinput to its original data.
1)Created one tabpanel with title.
2)Created all the input and its types.
3)Created Modal successfully.
4)Even tried with shinyjs::reset() funtion as well.
Code for Ui.R:
tabPanel(title="User Management",id ="user",shinyjs::useShinyjs(),
fluidRow(
column(5,textInput("uname","User Name")),
column(5,textInput("fname","Full Name"))),
fluidRow(
column(5,textInput("email","Email Id")),
column(5,numericInput("contactnum","Contactnumber",value=NULL))),
fluidRow(
column(5,selectInput("country", label = "Country:",
choices = list("India","USA"),
selected = 1)),
column(5,selectInput("state", label = "State:",
choices =list("Karnataka","Kerala"),
selected = 1))),
fluidRow(column(5,numericInput("zip","ZIP Code",value=NULL)),
fluidRow(
column(5,passwordInput("pwd1","Password")),
column(5,passwordInput("pwd2","Confirm Password"))),
fluidRow(
column(12,actionButton("userCreate", "Create User"),
style="color: #fff;
background-color: #337ab7; border-color: #2e6da4"))),
br(),
)
)
Server.R:
observeEvent(input$userCreate,{
if(postuser() == 200)
{
showModal(modalDialog(
title = "Success",
"User is successfully added!"
footer = tagList(
actionButton("Close", "Close")
)
)))
}
})
observeEvent(input$Close,{
reset("user")
}
)
Update and Tries:
Even tried with shinyjs::reset("user") funtion and shinyjs::js$reset("user")function as well.
Please help me out with this . And i need logical code for list of all the counties and states.
Thanks in Advance
Try
observeEvent(input$Close,{
#reset("user")
shinyjs::reset("uname")
shinyjs::reset("fname")
#the remaining fields id's you would like to reset
}
The problem was giving the wrong div id's to reset, hence nothing happened after click close. To understand what I'm talking about have a look at
print(tabPanel(title="User Management",id ="user",shinyjs::useShinyjs(),
fluidRow(
column(5,textInput("uname","User Name")),
column(5,textInput("fname","Full Name")))))