'Dynamically update tag value when dateinput changes
Is it possible to update a tag value when dateInput is changed by a user? Maybe something like force, eventReactive, reactivevalue or stop lazy evaluation?
library(shiny)
library(lubridate)
library(tidyverse)
library(DT)
data <- data.frame(
date=seq.Date(from=dmy("1/1/2022"),to=dmy("31/1/2022"),by="day"),
y=round(rnorm(n=31,mean=0,sd=2),2)
)
date_selected <- ""
# fn_lookup(date_in="")
fn_lookup <- function(date_in){
if(length(date_in)>0){
y=(data %>% filter(date==dmy(date_in)))$y
}else{
y=""
}
return(y)
}
ui <- fluidPage(
fluidRow(
column(12,actionButton(inputId="edit_table",label="edit",icon=icon("edit")))
),
fluidRow(
br(),
br(),
column(12,DT::dataTableOutput('table')))
)
server <- function(input, output) {
output$table <- DT::renderDataTable(data)
observeEvent(input$edit_table,{
date_selected <- eventReactive(input$ad1, { input$ad1 })
showModal(modalDialog(
tagList(
div(style="display:inline-block;",
dateInput(inputId="ad1",label="Date",value="2022-1-15",format="dd/mm/yyyy")
),
div(style="display:inline-block;",
tags$label("value static"),
tags$input(id = "ad2", type = "text", class="form-control",value = fn_lookup("15/1/2022"))
),
div(style="display:inline-block;",
tags$label("value dynamic"),
#dynamically update this tag value when the date input changes
tags$input(id = "ad3", type = "text", class="form-control",value = fn_lookup(input$ad1))
),
div(style="display:inline-block;",
tags$label("value dynamic 2"),
#dynamically update this tag value when the date input changes
# tags$input(id = "ad3", type = "text", class="form-control",value = fn_lookup(date_selected))
)
),
footer = tagList(
modalButton("Cancel"),
actionButton(inputId="check", "Check",icon=icon("check"))
),
easyClose = TRUE
))
})
}
shinyApp(ui, server)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
