I have created the following shiny App in R
First we import the necessary libraries
library(shiny)
library(shinyBS)
The next step is to create a UI as follows
ui = fluidPage( sidebarLayout( sidebarPanel(sliderInput("bins", "Number of bins:", min = 1, max =
50,value = 30), selectInput(inputId = "Select1", label = "Select1", choices = c('A', 'B', 'C'),
selected = "A"), selectInput(inputId = "Select2", label = "Select2", choices = c('A1', 'B1', 'C1'),
selected = "A1"), bsTooltip("bins", "Read", "right", options = list(container = "body")) ),
mainPanel(uiOutput("namelist") ) ))
We now create the Server as follows
server =function(input, output, session) {
content<-reactive({
input$Select2
})
output$namelist<-renderUI({
textInput(inputId = "text1", label =input$Select1)
})
addPopover(session, "namelist", "Data", content =content() , trigger = 'click') }
shinyApp(ui, server)
The App on running will create a slider and two select boxes and an output that reacts dynamically to user input. the tooltip displays the bubble with read when one hovers over the slider. I am unable to get the addpopover function to work. It should work such that based on the input of select 2, the text rendered in the popover message box should change. The App is crashing . When i place the addpopover command within a reactive environment, I am the renderUI functions output- namely the textbox disappears. I request someone to help me here.
You can wrap addPopover
in observe
or observeEvent
. I would prefer observeEvent
, as recommended here.
addPopover
will be updated each time content()
changes, which is what we want since this popover is supposed to show content()
. However, there is something strange about the behaviour of this popover (clicks are sometimes ineffective) but I guess this is not related to your app in particular.
library(shiny)
library(shinyBS)
ui = fluidPage(sidebarLayout(
sidebarPanel(
sliderInput(
"bins",
"Number of bins:",
min = 1,
max =
50,
value = 30
),
selectInput(
inputId = "Select1",
label = "Select1",
choices = c('A', 'B', 'C'),
selected = "A"
),
selectInput(
inputId = "Select2",
label = "Select2",
choices = c('A1', 'B1', 'C1'),
selected = "A1"
),
bsTooltip("bins", "Read", "right", options = list(container = "body"))
),
mainPanel(uiOutput("namelist"))
))
server =function(input, output, session) {
content<-reactive({
input$Select2
})
output$namelist<-renderUI({
textInput(inputId = "text1", label = input$Select1)
})
observeEvent(content(), {
addPopover(session, "namelist", "Data", content = content() , trigger = 'click')
})
}
shinyApp(ui, server)