Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mark function doesn't work for reactive elements #6

Open
Emma-Palm opened this issue Nov 2, 2022 · 1 comment
Open

mark function doesn't work for reactive elements #6

Emma-Palm opened this issue Nov 2, 2022 · 1 comment

Comments

@Emma-Palm
Copy link

Hello,

I've been trying to use your package to highlight some text based on data in a data frame. I want to build a shiny app where the user can select the text entry they want to look at and the text is automatically highlighted based on the information in another column. When I don't include the option to change the displayed text the highlighting works well, however when I include the filtering option the text doesn't get marked anymore. Here is some example code and data:

Marker_package_example_data.csv

This works:
library(tidyverse)
library(shiny)
library(marker)

data <- read_delim("Marker package example data.csv")
lorem <- data$Text[1]

ui <- fluidPage(

       mainPanel(useMarker(),
                 tags$head(
                   tags$style(
                     ".red{background-color:#FFB8C3;}.blue{background-color:#6ECFEA;}"
                   )
                 ),
                 p(id = "test", lorem)
       )

)
)

server <- function(input, output){

marker <- marker$new("#test")

observe(marker$
unmark()$
mark(data$Origin[1], className = "blue"))

observe(marker$
unmark()$
mark(data$Name[1], className = "red"))

}

shinyApp(ui, server)

This doesn't work:
library(tidyverse)
library(shiny)
library(marker)

data <- read_delim("Marker_package_example_data.csv")

ui <- fluidPage(
tabPanel(title = "Text",
sidebarPanel(
selectInput("Name_selector", "Select a Name", choices = data$Name, selected = data$Name[1])
),
mainPanel(useMarker(),
tags$head(
tags$style(
".red{background-color:#FFB8C3;}.blue{background-color:#6ECFEA;}"
)
),
p(id = "test", textOutput("marked_data"))#This is what is causing at least part of the problem
)

)
)

server <- function(input, output){

Reactive_data <- reactive(
data%>%
filter(Name == input$Name_selector)
)

output$marked_data <- renderText({
Reactive_data()$Text
})

marker <- marker$new("#test")

observe(marker$
unmark()$
mark(Reactive_data()$Origin, className = "blue"))

observe(marker$
unmark()$
mark(Reactive_data()$Name, className = "red"))

}

shinyApp(ui, server)

@roman-tremmel
Copy link

try htmlOutput instead of the textOutput.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants