## embed website into shinyapp ``` library(shiny) members <- data.frame(name=c("Name 1", "Name 2"), nr=c('BCRA1','FITM2')) ui <- fluidPage(titlePanel("Getting Iframe"), sidebarLayout( sidebarPanel( fluidRow( column(6, selectInput("Member", label=h5("Choose a option"),choices=c('BCRA1','FITM2')) ))), mainPanel(fluidRow( htmlOutput("frame") ) ) )) server <- function(input, output) { observe({ query <- members[which(members$nr==input$Member),2] test <<- paste0("https://yingxiaoyan.gitlab.io/YingxiaoYan.com/",query) }) output$frame <- renderUI({ input$Member my_test <- tags$iframe(src=test, height=600, width=535) print(my_test) my_test }) } shinyApp(ui, server) ``` ``` library(shiny) library(shinydashboard) ui <- dashboardPage( dashboardHeader(title = "Website Embedder"), dashboardSidebar( sidebarMenu( menuItem("Home", tabName = "home", icon = icon("home")), menuItem("Embedded Website", tabName = "website", icon = icon("globe")) ) ), dashboardBody( tabItems( tabItem(tabName = "home", h2("Welcome to the Website Embedder"), p("Click on 'Embedded Website' in the sidebar to view an embedded website.") ), tabItem(tabName = "website", h2("Embedded Website"), fluidRow( column(width = 12, tags$iframe(src = "https://yingxiaoyan.gitlab.io/YingxiaoYan.com/", width = "100%", height = "600px", frameborder = "0") ) ) ) ) ) ) server <- function(input, output) { # Server logic can be added here if needed } shinyApp(ui, server) ``` ## The embedding seem working in this one. but reclicking does not work ``` library(shiny) library(httr) ui <- fluidPage( titlePanel("Simple Web Browser in Shiny"), sidebarLayout( sidebarPanel( textInput("url", "Enter URL:", value = "https://yingxiaoyan.gitlab.io/YingxiaoYan.com/"), actionButton("go", "Go") ), mainPanel( uiOutput("web_content") ) ) ) server <- function(input, output, session) { web_content <- reactiveVal() observeEvent(input$go, { req(input$url) tryCatch({ response <- GET(input$url) content <- content(response, "text") # Modify links to prevent them from opening in new windows content <- gsub('target="_blank"', '', content) web_content(content) }, error = function(e) { web_content(paste("Error loading page:", e$message)) }) }) output$web_content <- renderUI({ HTML(web_content()) }) } shinyApp(ui, server) ``` ``` library(shiny) ui <- fluidPage( titlePanel("Browser test"), sidebarLayout( sidebarPanel( shiny::actionButton(inputId = "gen_report", label = "Generate Report") ), mainPanel( ) )) server <- function(input, output) { observeEvent(input$gen_report,{ browseURL("https://www.r-project.org") }) } shinyApp(ui = ui, server = server) ```