I got this error.
Listening on http://127.0.0.1:4404
Warning: Error in $: Can't access reactive value 'barcode' outside of reactive consumer.
Do you need to wrap inside reactive() or observe()?
53:
Error in input$barcode :
Can't access reactive value 'barcode' outside of reactive consumer.
Do you need to wrap inside reactive() or observe()?
I'm trying to get a user input from a textinput. That input should be splitted at the seperator ";". And the second half should create the barcode in following.
So this is my code
library(shinyjs)
library(dplyr)
library(stringr)
# Define UI for application that draws a histogram
ui <- fluidPage(
useShinyjs(),
headerPanel(title = "QR - Split and generate"),
sidebarLayout(
sidebarPanel(
textInput("barcode","Enter the Barcode"),
actionButton("button","GO"),
imageOutput("svgplot"),
),
mainPanel(
textOutput("barcode_full"),
textOutput("barcode_first"),
#textOutput("barcode_second")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
observeEvent(input$button,{
session$sendCustomMessage(type = 'testmessage',
message = 'Thank you for clicking')
})
#Split macht probleme
barcode_first1<-input$barcode
barcode_first<-strsplit(barcode_first1,";")[[1]]
#barcode_first1 <- reactive({strsplit(input$barcode,";")[[1:1]]})
# QR <- eventReactive(input$barcode, {
# qrcode::qr_code(input$barcode)
#})
QR<- eventReactive(barcode_first[1],{
qrcode::qr_code(barcode_first1[1])
})
output$svgplot <- renderImage({
txt <- isolate(barcode_first1[1])
tf <- tempfile(fileext = ".svg")
qrcode::generate_svg(QR(), tf, size = 100, foreground = "black", background = "white", show = FALSE)
list(
src = normalizePath(tf),
contentType = "image/svg+xml",
width = 100, height = 100,
alt = paste("My QR code:", sQuote(txt, FALSE))
)
}, deleteFile = TRUE)
#outputs
output$barcode_full <- {(
renderText(input$barcode)
)}
output$barcode_first <- {(
renderText(barcode_first1[1])
)}
output$barcode_second <- {(
renderText(input$barcode)
)}
}
# Run the application
shinyApp(ui = ui, server = server)