Format change in CSV r

...
Whenever I try to pull value (website link) from csv file I get ( \) before each ( " ) as shown in the two photos below, how I can fix this problem

I changed encoding to "UTF-8" but still, nothing happened


I suspect the back slashes are not in the data and they are shown because the text in the csv is in quotes. For example:

x <- '"text_in_quotes"'
print(x)
[1] "\"text_in_quotes\""
1 Like

Thank you, but I need the final result to be in quotes in order to use it

It is in quotes; that is what is being shown with the notation \". Have you encountered a problem with using the data?

I want to enable this Actionbutton functioning:

actionButton(inputId='more', label="Learn More",icon = icon("th"),
onclick = textOutput('more_button'))

the problem is 'more_button' value needs to be in quotes, whenever I render the text I get it without quotes

I tried these solutions but none of them managed to solve the problem:

first try :

more_button_text <- reactive({
if (input$mySliderText %in% info_360$press )
{
info_360 %>%
filter(press == input$mySliderText)%>%
pull(more)

the value of more is:

"window.open('http://nilebasin.org/nileis/system/files/DSS%20Booklet_web.pdf')"

}

})

server <- function(input, output) {
output$more_button <- renderText({ paste0('"', more_button_text(), '"') })
}

second try :

more_button_text <- reactive({
if (input$mySliderText %in% info_360$press )
{
info_360 %>%
filter(press == input$mySliderText)%>%
pull(more)

}

})

more_button_text1 <- reactive({

cat(sprintf('"%s",',more_button_text() ))

})

server <- function(input, output) {
output$more_button <- renderText({ paste0('"', more_button_text1(), '"') })
}

or suggest to me please any alternative way to make this action button work?

It is not clear to me where you want the text to appear. In the app below, clicking the Learn More button toggles the appearance of the text from the more column of the csv file. My csv file only has the header row and one data row

press,more
"A","window.open('http://nilebasin.org/nileis/system/files/DSS%20Booklet_web.pdf')"

Because of that, I hard coded the value in the filter() function.
The toggling works because the action button returns a value that increments with each click. That value is accessed with the reference input$more.
Is this the sort of thing you want to do?

library(shiny)

info_360 <- read.csv("Data/360_photos.csv")

ui <- fluidPage(
  
  actionButton(inputId='more', label="Learn More",icon = icon("th")),
  textOutput("more_button")
)

server <- function(input, output, session) {
  MORE <- eventReactive(input$more, 
                        if((input$more %% 2) == 1) {
                          info_360 %>%
                          filter(press == "A") %>%
                          pull(more)
                        } else {""}
  )
  output$more_button <- renderText(MORE())
}
shinyApp(ui, server)

Thank you very much, I do appreciate your efforts.
my main purpose of the action button is to redirect the user to a website by clicking, so the main thing here (onclick= textOutput('more_button')), more_button should be a website link with quotes exactly like this
"window.open('http://nilebasin.org/nileis/system/files/DSS%20Booklet_web.pdf')"

This code, with the csv set up as before, opens the PDF document in my browser. I got the js code idea from here:

library(shiny)
library(shinyjs)
info_360 <- read.csv("Data/360_photos.csv")

ui <- fluidPage(
  useShinyjs(),
  actionButton(inputId='more', label="Learn More",icon = icon("th"))
)

server <- function(input, output, session) {
  MORE <- eventReactive(input$more, 
                        
                          info_360 %>%
                          filter(press == "A") %>%
                          pull(more)
  )
 onclick("more", runjs(paste0("window.open(",MORE(),")")))
}
shinyApp(ui, server)
1 Like

Now it works perfectly :ok_hand:t2:
Thank you so much for your valuable help, you saved me :smiling_face_with_three_hearts:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.