Skip to content

Instantly share code, notes, and snippets.

@seankross
Created May 26, 2017 20:24
Show Gist options
  • Save seankross/eb0da1f3a0bffbd1c62dd572bd799d8d to your computer and use it in GitHub Desktop.
Save seankross/eb0da1f3a0bffbd1c62dd572bd799d8d to your computer and use it in GitHub Desktop.
#' @importFrom shiny
#' @import miniUI
codefinch_app <- function(){
ui <- miniPage(
gadgetTitleBar("Codefinch: Tweet Your Code",
right = miniTitleBarButton("tweet_it", "Send Tweet", primary = TRUE)),
miniContentPanel(
fillRow(flex = c(2, 3),
fillCol(
uiOutput("status_box"),
textOutput("chars"),
checkboxInput("gist_url", "Include Gist URL in Image?"),
selectInput("highlight", "Select Highlight", choices = c(
"default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn","haddock"
)),
actionButton("update_preview", "Update Code Preview")
),
fillCol(imageOutput("code_png"))
)
# fillCol(flex = c(5, 2),
# imageOutput("code_png", height = "100%"),
# fillRow(flex = c(2, 1),
# fillCol(textAreaInput("status", label = NULL, width = "100%", height = "100%",
# resize = "both"),
# fillRow(textOutput("chars"),
# checkboxInput("gist_url", "Include Gist URL?"))
# ),
# selectInput("highlight", "Select Highlight", choices = c(
# "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn","haddock"
# ))
# )
# )
)
)
server <- function(input, output){
img_path <- tempfile(fileext = ".png")
ctx <- getSourceEditorContext()
path <- tempfile(fileext = ".R")
raw_code <- ctx$contents
writeLines(raw_code, path)
gist_obj <- gist_create(path, browse = FALSE)
observeEvent(input$update_preview, ignoreNULL = FALSE, {
ctx <- getSourceEditorContext()
raw_code <- ctx$contents
writeLines(raw_code, path)
gist_obj %>%
update_files(path) %>%
update()
create_image(highlight = input$highlight, image_path = img_path)
})
# img <- reactive({
# create_image(highlight = input$highlight)
# })
output$status_box <- renderUI({
textAreaInput("status", label = NULL, width = "100%", height = "100%",
resize = "both", value = gist_obj$html_url)
})
output$code_png <- renderImage({
input$update_preview
list(src = img_path, width = "100%")
})
output$chars <- renderText({
140 - nchar(input$status)
})
}
runGadget(ui, server, viewer = paneViewer())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment